Wrong Answer
foo.cc: In function 'int main()': foo.cc:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i=0;i<e2[no].size();i++){ ~^~~~~~~~~~~~~~ foo.cc:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j=0;j<e1[i].size();i++){ ~^~~~~~~~~~~~~ foo.cc:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i=0;i<e1[no].size();i++){ ~^~~~~~~~~~~~~~ 自豪的采用 HydroJudge 进行评测(github.com/hydro-dev/HydroJudge)
{"receive":"2020-08-10T03:16:03.217Z","handle":"2020-08-10T03:16:03.217Z","cache_start":"2020-08-10T03:16:03.226Z","read_cases":"2020-08-10T03:16:03.389Z","judge":"2020-08-10T03:16:03.397Z","done":"2020-08-10T03:16:04.722Z"}
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,s,t;
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0') f^=(c=='-'),c=getchar();
while(c>'/') x=(x<<3)+(x<<1)+(c^'0'),c=getchar();
return f?x:-x;
}
vector<int>e1[10010],e2[10010];
int bo[10010],vs[10010];
int main(){
n=read();m=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
e1[u].push_back(v);
e2[v].push_back(u);
}
queue<int> q1;
s=read();
t=read();
bo[t]=1;
q1.push(t);
while(!q1.empty()){
int no=q1.front();
q1.pop();
for(int i=0;i<e2[no].size();i++){
int to=e2[no][i];
if(!bo[to]){
q1.push(to);
bo[to]=1;
}
}
}
for(int i=1;i<=n;i++){
if(bo[i]){
for(int j=0;j<e1[i].size();i++){
int to=e1[i][j];
if(!bo[to])
bo[i]=0;
}
}
}
if(!bo[s]){
puts("-1");
return 0;
}
vs[s]=1;
q1.push(s);
while(!q1.empty()){
int no=q1.front();
q1.pop();
for(int i=0;i<e1[no].size();i++){
int to=e1[no][i];
if(bo[to]&&!vs[to]){
q1.push(to);
vs[to]=vs[no]+1;
}
}
}
printf("%d\n",vs[t]-1);
return 0;
}
信息
- 递交者
- 类型
- 递交
- 题目
- P1025 寻找道路
- 题目数据
- 下载
- 语言
- C++
- 递交时间
- 2019-11-12 17:41:58
- 评测时间
- 2020-08-10 11:16:03
- 评测机
- 分数
- 20
- 总耗时
- 59ms
- 峰值内存
- 5.559 MiB