记录详情

Wrong Answer

/in/foo.cc: In function 'int bfs()':
/in/foo.cc:21:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=0;i<adj[u].size();i++)
                ~^~~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 8ms 2.875 MiB
#2 Wrong Answer 10ms 3.105 MiB
#3 Wrong Answer 54ms 3.75 MiB
#4 Wrong Answer 379ms 10.848 MiB

代码

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define N 100010
using namespace std;
int n,m,dis[N];
vector <int> adj[N];
queue <int> q;
int bfs()
{
	memset(dis,-1,sizeof(dis));
	dis[1]=0;
	q.push(1);
	while (!q.empty())
	{
		int u=q.front();
		if (u==n) break;
		q.pop();
		for (int i=0;i<adj[u].size();i++)
			if (!~dis[adj[u][i]])
				dis[adj[u][i]]=dis[u]+1,q.push(dis[adj[u][i]]);
	}
	return dis[n];
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1,u,v;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
	}
	printf("%d",bfs());
	return 0;
} 

信息

递交者
类型
递交
题目
链式前向星/BFS 板题
题目数据
下载
语言
C++
递交时间
2017-11-19 10:44:55
评测时间
2017-11-19 10:44:55
评测机
分数
0
总耗时
453ms
峰值内存
10.848 MiB