用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#14362 | #1079. 1-11D. JM的神庙逃亡 | Accepted | 100 | 792 ms | 8748 K | C++ / 1.2 K | sl的女朋友 | 2019-07-08 0:39:04 |
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 500005;
const int INF = 2147483647;
int n, m, s, x, y, z, cnt;
int to[maxn], nxt[maxn], head[maxn], val[maxn], dis[maxn];
bool vis[maxn];
void add(int x, int y, int z) {
to[++cnt] = y;
nxt[cnt] = head[x];
head[x] = cnt;
val[cnt] = z;
}
void dijkstra(int s) {
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
dis[s] = 0;
q.push(make_pair(0, s));
while (!q.empty()) {
int p = q.top().second;
q.pop();
if (vis[p])
continue;
vis[p] = 1;
for (int i = head[p]; i; i = nxt[i])
if (dis[p] + val[i] < dis[i[to]]) {
dis[i[to]] = dis[p] + val[i];
q.push(make_pair(dis[i[to]], i[to]));
}
}
return;
}
int main() {
int a, b;
scanf("%d%d", &n, &m);
cin >> a >> b;
s = a;
for (int i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
z = 1;
add(x, y, z);
add(y, x, z);
}
for (int i = 1; i <= n; i++) dis[i] = INF;
dijkstra(s);
if (dis[b] == INF)
cout << -1 << endl;
else
cout << dis[b] + 1 << endl;
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