#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=200000+5;
int n,m;
int s,d,a,b;
vector<int>g[N];
int di[2][N];
void build(int k,int go)
{
for(int i=1;i<=n;i++)
{
di[k][i]=-1;
}
di[k][go]=0;
queue<int>q;
q.push(go);
while(!q.empty())
{
int nod=q.front();
q.pop();
for(auto &nou:g[nod])
{
if(di[k][nou]==-1)
{
di[k][nou]=1+di[k][nod];
q.push(nou);
}
}
}
}
int main()
{
// freopen("input","r",stdin);
// freopen("output","w",stdout);
cin>>n>>m;
cin>>s>>d>>a>>b;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
build(0,s);
build(1,d);
int a1=di[0][a],a2=di[0][b];
int b1=di[1][a],b2=di[1][b];
int x=max(a1,a2);
int y=max(b1,b2);
int ans=y-x;
if(ans>=0)
{
cout<<ans<<"\n";
}
else
{
cout<<"-1\n";
}
return 0;
cout<<a1<<" "<<a2<<" ; "<<b1<<" "<<b2<<"\n";
return 0;
}
/**
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
5260 KB |
Output is correct |
3 |
Correct |
5 ms |
5260 KB |
Output is correct |
4 |
Incorrect |
6 ms |
5260 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
5260 KB |
Output isn't correct |
6 |
Correct |
5 ms |
5260 KB |
Output is correct |
7 |
Correct |
6 ms |
5284 KB |
Output is correct |
8 |
Incorrect |
5 ms |
5284 KB |
Output isn't correct |
9 |
Correct |
5 ms |
5284 KB |
Output is correct |
10 |
Correct |
6 ms |
5284 KB |
Output is correct |
11 |
Incorrect |
5 ms |
5284 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
13 |
Correct |
5 ms |
5284 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
15 |
Correct |
6 ms |
5284 KB |
Output is correct |
16 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
19 |
Correct |
6 ms |
5284 KB |
Output is correct |
20 |
Correct |
5 ms |
5328 KB |
Output is correct |
21 |
Incorrect |
6 ms |
5332 KB |
Output isn't correct |
22 |
Correct |
6 ms |
5356 KB |
Output is correct |
23 |
Correct |
6 ms |
5356 KB |
Output is correct |
24 |
Incorrect |
7 ms |
5356 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
6908 KB |
Output is correct |
2 |
Incorrect |
60 ms |
7636 KB |
Output isn't correct |
3 |
Correct |
49 ms |
7636 KB |
Output is correct |
4 |
Incorrect |
63 ms |
7672 KB |
Output isn't correct |
5 |
Incorrect |
46 ms |
7672 KB |
Output isn't correct |
6 |
Incorrect |
46 ms |
7672 KB |
Output isn't correct |
7 |
Correct |
47 ms |
7672 KB |
Output is correct |
8 |
Correct |
50 ms |
7672 KB |
Output is correct |
9 |
Incorrect |
80 ms |
7672 KB |
Output isn't correct |
10 |
Correct |
334 ms |
12028 KB |
Output is correct |
11 |
Incorrect |
95 ms |
12028 KB |
Output isn't correct |
12 |
Correct |
126 ms |
12028 KB |
Output is correct |
13 |
Incorrect |
107 ms |
12028 KB |
Output isn't correct |
14 |
Correct |
84 ms |
12028 KB |
Output is correct |
15 |
Correct |
128 ms |
12028 KB |
Output is correct |
16 |
Incorrect |
117 ms |
12028 KB |
Output isn't correct |
17 |
Correct |
112 ms |
12028 KB |
Output is correct |
18 |
Incorrect |
109 ms |
12028 KB |
Output isn't correct |
19 |
Correct |
204 ms |
12028 KB |
Output is correct |
20 |
Incorrect |
415 ms |
13564 KB |
Output isn't correct |
21 |
Incorrect |
169 ms |
13564 KB |
Output isn't correct |
22 |
Correct |
129 ms |
13564 KB |
Output is correct |
23 |
Correct |
178 ms |
13564 KB |
Output is correct |
24 |
Correct |
165 ms |
13564 KB |
Output is correct |
25 |
Incorrect |
160 ms |
13564 KB |
Output isn't correct |
26 |
Correct |
142 ms |
13564 KB |
Output is correct |
27 |
Correct |
164 ms |
13564 KB |
Output is correct |
28 |
Correct |
183 ms |
13564 KB |
Output is correct |
29 |
Correct |
257 ms |
13564 KB |
Output is correct |
30 |
Incorrect |
429 ms |
14212 KB |
Output isn't correct |
31 |
Incorrect |
200 ms |
14212 KB |
Output isn't correct |
32 |
Correct |
176 ms |
14212 KB |
Output is correct |
33 |
Correct |
161 ms |
14212 KB |
Output is correct |
34 |
Incorrect |
208 ms |
14212 KB |
Output isn't correct |
35 |
Incorrect |
184 ms |
14212 KB |
Output isn't correct |
36 |
Incorrect |
191 ms |
14212 KB |
Output isn't correct |
37 |
Incorrect |
209 ms |
14212 KB |
Output isn't correct |
38 |
Correct |
215 ms |
14212 KB |
Output is correct |
39 |
Correct |
226 ms |
14212 KB |
Output is correct |
40 |
Incorrect |
351 ms |
14328 KB |
Output isn't correct |
41 |
Correct |
531 ms |
16764 KB |
Output is correct |