用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20891 | #1079. 1-11D. JM的神庙逃亡 | Accepted | 100 | 874 ms | 8380 K | C++ / 990 B | kong | 2019-08-16 15:08:33 |
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
vector<int> graph[MAXN];
bool visited[MAXN];
int dist[MAXN];
inline void add(int u, int v) { graph[u].push_back(v); }
int bfs(int st, int ed) {
queue<int> q;
q.push(st);
visited[st] = true;
dist[st] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if (!visited[v]) {
q.push(v);
visited[v] = true;
dist[v] = dist[u] + 1;
}
}
}
return (dist[ed] == INF ? -1 : dist[ed]);
}
int main() {
int n, m, a, b;
scanf("%d%d%d%d", &n, &m, &a, &b);
for (int i = 0; i < MAXN; i++) graph[i].clear();
memset(visited, false, sizeof(visited));
memset(dist, INF, sizeof(dist));
int u, v;
while (m--) {
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
int ans;
ans = bfs(a, b);
cout << ans;
return 0;
}
9 31 7 3
3 2
7 8
7 6
2 1
3 5
3 4
7 3
9 6
9 1
8 2
8 5
8 3
5 1
9 7
1 7
9 3
6 5
6 2
1 8
4 5
5 7
5 9
8 9
<33 bytes omitted>
用户输出
2
系统信息
Exited with return code 0
用户输出
2
系统信息
Exited with return code 0
用户输出
4
系统信息
Exited with return code 0
用户输出
3
系统信息
Exited with return code 0
12 21 7 11
7 9
4 6
6 11
7 11
2 7
12 10
12 7
5 3
1 12
11 12
4 12
7 8
9 1
9 12
3 12
8 4
1 10
5 7
8 2
9
<8 bytes omitted>
用户输出
2
系统信息
Exited with return code 0
用户输出
2
系统信息
Exited with return code 0
用户输出
-1
系统信息
Exited with return code 0
用户输出
4
系统信息
Exited with return code 0
117224 195547 53440 106368
45993 67089
32498 45756
75092 58958
37615 95200
111884 9773
49730 99143
3
<2366924 bytes omitted>
用户输出
11
系统信息
Exited with return code 0
148425 61215 131631 74257
56343 1160
85619 99681
118948 23773
715 9349
127694 84850
54522 111432
555
<765069 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
150724 129862 93020 113722
98339 133164
122267 372
43451 31705
119513 45945
89454 110229
37343 10158
<1626819 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
144285 197897 98101 73161
103346 29386
94836 85444
69600 64976
56173 134340
21214 55410
98256 10490
<2465627 bytes omitted>
用户输出
13
系统信息
Exited with return code 0
109432 197520 91361 50079
4303 53737
77827 79082
12715 58750
2665 89721
73008 85932
74589 31977
1730
<2364035 bytes omitted>
用户输出
11
系统信息
Exited with return code 0
200000 199999 1 200000
158842 145192
29489 92185
180652 87805
105086 152681
194223 126601
131084 136
<2577701 bytes omitted>
用户输出
15203
系统信息
Exited with return code 0
200000 199999 156495 127328
161312 5188
178299 77672
121736 52092
178299 164923
144187 178299
79068
<2616702 bytes omitted>
用户输出
13095
系统信息
Exited with return code 0
200000 199999 51655 81786
61304 139431
54934 61304
61304 19579
61304 43860
61304 169518
61304 138116
<2488809 bytes omitted>
用户输出
3
系统信息
Exited with return code 0
200000 200000 156389 39194
28695 142509
141378 154650
99870 42942
86312 188136
142924 197189
81309 9
<2577658 bytes omitted>
用户输出
15
系统信息
Exited with return code 0