用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#17534 | #1079. 1-11D. JM的神庙逃亡 | Accepted | 100 | 2635 ms | 13168 K | C++ 11 / 738 B | dinghaoran | 2019-07-12 19:06:30 |
#include <bits/stdc++.h>
using namespace std;
#define MAX 200100
#define INF 200100
typedef pair<int, int> e;
int dist[MAX], n;
vector<e> aj[MAX];
priority_queue<e> q;
int main() {
int n, m, a, b, u, v;
scanf("%d%d%d%d", &n, &m, &a, &b);
for (int i = 1; i <= m; ++i) scanf("%d%d", &u, &v), aj[u].push_back(e(v, 1)), aj[v].push_back(e(u, 1));
for (int i = 2; i <= n; ++i) dist[i] = INF;
dist[a] = 0;
q.push(e(a, 0));
while (!q.empty()) {
int num = q.top().first, dis = q.top().second;
q.pop();
if (dis <= dist[num])
for (e i : aj[num])
if (dist[i.first] > dist[num] + i.second)
dist[i.first] = dist[num] + i.second, q.push(e(i.first, dist[i.first]));
}
if (dist[b] == INF)
printf("-1\n");
else
printf("%d", dist[b] + 1);
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