#include <bits/stdc++.h>
using namespace std;
inline int in() {
int result = 0;
char ch = getchar_unlocked();
while(true) {
if(ch >= '0' && ch <= '9')
break;
ch = getchar_unlocked();
}
result = ch-'0';
while(true) {
ch = getchar_unlocked();
if (ch < '0' || ch > '9')
break;
result = result*10 + (ch - '0');
}
return result;
}
inline void out(int x) {
if(!x) {
putchar_unlocked('0');
return;
}
if(x<0) {
putchar_unlocked('-');
x=-x;
}
int rev=x, c=0;
while(!(rev%10)) {
++c;
rev/=10;
}
rev=0;
while(x) {
rev=rev*10+x%10;
x/=10;
}
while(rev) {
putchar_unlocked(rev%10+'0');
rev/=10;
}
while(c--)
putchar_unlocked('0');
}
const int mxN=2e5;
int n, m, s, d, a, b, da[mxN], db[mxN], qu[mxN], qh, qt, dp[mxN];
vector<int> adj[mxN];
inline void bfs(int s, int dist[mxN]) {
qh=qt=0;
memset(dist, 0x3F, 4*n);
qu[qt++]=s;
dist[s]=0;
while(qh<qt) {
int u=qu[qh++];
for(int v : adj[u]) {
if(dist[v]>n) {
qu[qt++]=v;
dist[v]=dist[u]+1;
}
}
}
}
int cdp(int u) {
if(!dp[u]) {
dp[u]=da[u];
for(int v : adj[u])
if(da[v]==da[u]-1&&da[v]==db[v])
dp[u]=min(cdp(v), dp[u]);
}
return dp[u];
}
int main() {
n=in(), m=in(), s=in()-1, d=in()-1, a=in(), b=in();
while(m--) {
int u=in()-1, v=in()-1;
adj[u].push_back(v);
adj[v].push_back(u);
}
bfs(a, da);
bfs(b, db);
if(da[s]!=db[s]||da[d]!=db[d])
out(max(min(da[d]-da[s], db[d]-db[s]), -1));
else
out(max(da[d]-da[s]-(cdp(d)<cdp(s)), -1));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
8 ms |
4984 KB |
Partially correct |
2 |
Incorrect |
7 ms |
5092 KB |
Output isn't correct |
3 |
Partially correct |
9 ms |
5168 KB |
Partially correct |
4 |
Incorrect |
8 ms |
5204 KB |
Output isn't correct |
5 |
Partially correct |
9 ms |
5204 KB |
Partially correct |
6 |
Correct |
8 ms |
5272 KB |
Output is correct |
7 |
Incorrect |
7 ms |
5272 KB |
Output isn't correct |
8 |
Partially correct |
7 ms |
5272 KB |
Partially correct |
9 |
Incorrect |
6 ms |
5272 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
5272 KB |
Output isn't correct |
11 |
Incorrect |
11 ms |
5272 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
5272 KB |
Output isn't correct |
13 |
Incorrect |
7 ms |
5272 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
5272 KB |
Output isn't correct |
15 |
Incorrect |
8 ms |
5272 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
5272 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
5356 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
5356 KB |
Output isn't correct |
19 |
Incorrect |
7 ms |
5356 KB |
Output isn't correct |
20 |
Incorrect |
9 ms |
5360 KB |
Output isn't correct |
21 |
Incorrect |
7 ms |
5360 KB |
Output isn't correct |
22 |
Correct |
8 ms |
5360 KB |
Output is correct |
23 |
Incorrect |
10 ms |
5360 KB |
Output isn't correct |
24 |
Partially correct |
9 ms |
5360 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
7016 KB |
Output isn't correct |
2 |
Incorrect |
38 ms |
7876 KB |
Output isn't correct |
3 |
Incorrect |
34 ms |
7876 KB |
Output isn't correct |
4 |
Incorrect |
43 ms |
7916 KB |
Output isn't correct |
5 |
Incorrect |
25 ms |
7916 KB |
Output isn't correct |
6 |
Incorrect |
36 ms |
7916 KB |
Output isn't correct |
7 |
Incorrect |
38 ms |
7916 KB |
Output isn't correct |
8 |
Incorrect |
39 ms |
7916 KB |
Output isn't correct |
9 |
Incorrect |
52 ms |
7916 KB |
Output isn't correct |
10 |
Incorrect |
109 ms |
12128 KB |
Output isn't correct |
11 |
Incorrect |
68 ms |
12128 KB |
Output isn't correct |
12 |
Incorrect |
72 ms |
12128 KB |
Output isn't correct |
13 |
Incorrect |
54 ms |
12128 KB |
Output isn't correct |
14 |
Correct |
52 ms |
12128 KB |
Output is correct |
15 |
Incorrect |
107 ms |
12128 KB |
Output isn't correct |
16 |
Incorrect |
111 ms |
12128 KB |
Output isn't correct |
17 |
Incorrect |
87 ms |
12128 KB |
Output isn't correct |
18 |
Incorrect |
96 ms |
12128 KB |
Output isn't correct |
19 |
Incorrect |
125 ms |
12128 KB |
Output isn't correct |
20 |
Incorrect |
211 ms |
14120 KB |
Output isn't correct |
21 |
Incorrect |
122 ms |
14120 KB |
Output isn't correct |
22 |
Incorrect |
104 ms |
14120 KB |
Output isn't correct |
23 |
Incorrect |
126 ms |
14120 KB |
Output isn't correct |
24 |
Incorrect |
120 ms |
14120 KB |
Output isn't correct |
25 |
Incorrect |
113 ms |
14120 KB |
Output isn't correct |
26 |
Incorrect |
78 ms |
14120 KB |
Output isn't correct |
27 |
Incorrect |
112 ms |
14120 KB |
Output isn't correct |
28 |
Incorrect |
134 ms |
14120 KB |
Output isn't correct |
29 |
Incorrect |
160 ms |
14120 KB |
Output isn't correct |
30 |
Incorrect |
218 ms |
14648 KB |
Output isn't correct |
31 |
Incorrect |
183 ms |
14648 KB |
Output isn't correct |
32 |
Incorrect |
130 ms |
14648 KB |
Output isn't correct |
33 |
Incorrect |
131 ms |
14648 KB |
Output isn't correct |
34 |
Incorrect |
170 ms |
14648 KB |
Output isn't correct |
35 |
Incorrect |
135 ms |
14648 KB |
Output isn't correct |
36 |
Incorrect |
103 ms |
14648 KB |
Output isn't correct |
37 |
Incorrect |
173 ms |
14648 KB |
Output isn't correct |
38 |
Incorrect |
134 ms |
14648 KB |
Output isn't correct |
39 |
Incorrect |
229 ms |
14648 KB |
Output isn't correct |
40 |
Incorrect |
248 ms |
14932 KB |
Output isn't correct |
41 |
Incorrect |
258 ms |
17240 KB |
Output isn't correct |