#include <bits/stdc++.h>
using namespace std;
int n,m,st1,st2,a,b;
vector <int> v[300005];
int lvl[300005][2];
void bs (int x,int y)
{
queue<int> q;
lvl[x][y]=1;
q.push(x);
while (!q.empty())
{
int node=q.front();
q.pop();
for (int i=0;i<v[node].size();i++)
{
if (!lvl[v[node][i]][y])
{
lvl[v[node][i]][y]=lvl[node][y]+1;
q.push(v[node][i]);
}
}
}
}
int main()
{
cin >>n>>m>>st1>>st2>>a>>b;
for (int i=0;i<m;i++)
{
int x,y;
cin >>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
bs(st1,1);
bs(st2,0);
vector <int> v1;
for (int i=0;i<v[a].size();i++)
{
if (v[a][i]!=b&&lvl[v[a][i]][0]<lvl[a][0])
v1.push_back(v[a][i]);
}
for (int i=0;i<v[b].size();i++)
{
if (v[b][i]!=a&&lvl[v[b][i]][0]<lvl[b][0])
v1.push_back(v[b][i]);
}
int ans=-1;
for (int i=0;i<v1.size();i++)
{
ans=max(ans,lvl[v1[i]][0]-lvl[v1[i]][1]);
}
cout <<ans;
return 0;
}
Compilation message
007.cpp: In function 'void bs(int, int)':
007.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[node].size();i++)
^
007.cpp: In function 'int main()':
007.cpp:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[a].size();i++)
^
007.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[b].size();i++)
^
007.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v1.size();i++)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7416 KB |
Output is correct |
2 |
Incorrect |
6 ms |
7416 KB |
Output isn't correct |
3 |
Partially correct |
7 ms |
7448 KB |
Partially correct |
4 |
Correct |
7 ms |
7452 KB |
Output is correct |
5 |
Partially correct |
7 ms |
7520 KB |
Partially correct |
6 |
Correct |
7 ms |
7520 KB |
Output is correct |
7 |
Partially correct |
7 ms |
7592 KB |
Partially correct |
8 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
9 |
Partially correct |
6 ms |
7836 KB |
Partially correct |
10 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
11 |
Incorrect |
7 ms |
7836 KB |
Output isn't correct |
12 |
Correct |
7 ms |
7836 KB |
Output is correct |
13 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
14 |
Incorrect |
7 ms |
7836 KB |
Output isn't correct |
15 |
Correct |
7 ms |
7836 KB |
Output is correct |
16 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
17 |
Correct |
7 ms |
7836 KB |
Output is correct |
18 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
19 |
Incorrect |
7 ms |
7836 KB |
Output isn't correct |
20 |
Partially correct |
8 ms |
7836 KB |
Partially correct |
21 |
Incorrect |
7 ms |
7836 KB |
Output isn't correct |
22 |
Correct |
8 ms |
7836 KB |
Output is correct |
23 |
Correct |
7 ms |
7836 KB |
Output is correct |
24 |
Partially correct |
7 ms |
7836 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
47 ms |
9232 KB |
Partially correct |
2 |
Correct |
65 ms |
9880 KB |
Output is correct |
3 |
Partially correct |
51 ms |
9880 KB |
Partially correct |
4 |
Correct |
65 ms |
10092 KB |
Output is correct |
5 |
Incorrect |
49 ms |
10092 KB |
Output isn't correct |
6 |
Incorrect |
51 ms |
10092 KB |
Output isn't correct |
7 |
Correct |
58 ms |
10092 KB |
Output is correct |
8 |
Correct |
54 ms |
10092 KB |
Output is correct |
9 |
Partially correct |
89 ms |
10092 KB |
Partially correct |
10 |
Incorrect |
388 ms |
14320 KB |
Output isn't correct |
11 |
Correct |
101 ms |
14320 KB |
Output is correct |
12 |
Partially correct |
133 ms |
14320 KB |
Partially correct |
13 |
Partially correct |
110 ms |
14320 KB |
Partially correct |
14 |
Correct |
95 ms |
14320 KB |
Output is correct |
15 |
Partially correct |
129 ms |
14320 KB |
Partially correct |
16 |
Incorrect |
132 ms |
14320 KB |
Output isn't correct |
17 |
Correct |
112 ms |
14320 KB |
Output is correct |
18 |
Incorrect |
121 ms |
14320 KB |
Output isn't correct |
19 |
Incorrect |
214 ms |
14320 KB |
Output isn't correct |
20 |
Partially correct |
439 ms |
15980 KB |
Partially correct |
21 |
Correct |
174 ms |
15980 KB |
Output is correct |
22 |
Partially correct |
159 ms |
15980 KB |
Partially correct |
23 |
Partially correct |
172 ms |
15980 KB |
Partially correct |
24 |
Partially correct |
174 ms |
15980 KB |
Partially correct |
25 |
Correct |
166 ms |
15980 KB |
Output is correct |
26 |
Partially correct |
147 ms |
15980 KB |
Partially correct |
27 |
Correct |
170 ms |
15980 KB |
Output is correct |
28 |
Correct |
186 ms |
15980 KB |
Output is correct |
29 |
Incorrect |
280 ms |
15980 KB |
Output isn't correct |
30 |
Partially correct |
441 ms |
16620 KB |
Partially correct |
31 |
Correct |
222 ms |
16620 KB |
Output is correct |
32 |
Partially correct |
190 ms |
16620 KB |
Partially correct |
33 |
Partially correct |
204 ms |
16620 KB |
Partially correct |
34 |
Correct |
239 ms |
16620 KB |
Output is correct |
35 |
Partially correct |
217 ms |
16620 KB |
Partially correct |
36 |
Partially correct |
190 ms |
16620 KB |
Partially correct |
37 |
Incorrect |
220 ms |
16620 KB |
Output isn't correct |
38 |
Correct |
225 ms |
16620 KB |
Output is correct |
39 |
Correct |
241 ms |
16620 KB |
Output is correct |
40 |
Partially correct |
370 ms |
16748 KB |
Partially correct |
41 |
Incorrect |
567 ms |
18888 KB |
Output isn't correct |