用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#46817 | #1079. 1-11D. JM的神庙逃亡 | Accepted | 100 | 1309 ms | 8168 K | C++ 11 / 859 B | 计试001-顾真榕 | 2020-11-30 17:47:34 |
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[200001];
int depth[200001];
queue<int> toVisit;
void bfs(int graphSize, int node, int destination) {
if (node == destination)
return;
for (auto i : graph[node])
if (depth[i] == -1) {
toVisit.push(i);
depth[i] = depth[node] + 1;
}
if (toVisit.empty())
return;
int temp = toVisit.front();
toVisit.pop();
bfs(graphSize, temp, destination);
}
int main() {
int n, m, a, b;
cin >> n >> m >> a >> b;
memset(depth, -1, sizeof(depth));
for (int i = 0; i < m; i++) {
int tempA, tempB;
cin >> tempA >> tempB;
graph[tempA].push_back(tempB);
graph[tempB].push_back(tempA);
}
depth[a] = 1;
bfs(n, a, b);
cout << depth[b] << endl;
}
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