# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105819 |
2019-04-15T07:53:23 Z |
Bodo171 |
007 (CEOI14_007) |
C++14 |
|
702 ms |
25720 KB |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax=200005;
vector<int> v[nmax];
int d[4][nmax];
int q[nmax];
int p,u,i,j,s,t,a,b,n,m,x,y,det_s,det_t,ans;
void bfs(int x,int wh)
{
q[u=1]=x;d[wh][x]=1;
for(p=1;p<=u;p++)
{
x=q[p];
for(i=0;i<v[x].size();i++)
if(!d[wh][v[x][i]])
{
d[wh][v[x][i]]=d[wh][x]+1;
q[++u]=v[x][i];
}
}
}
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>m;
cin>>s>>t>>a>>b;
for(i=1;i<=m;i++)
{
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
bfs(s,0);
bfs(t,1);
bfs(a,2);
bfs(b,3);
det_s=0;det_t=0;
for(i=1;i<=n;i++)
{
if(d[0][i]+d[2][i]-1==d[0][a]&&d[0][i]+d[3][i]-1==d[0][b])
det_s=max(det_s,d[0][i]);
if(d[1][i]+d[2][i]-1==d[1][a]&&d[1][i]+d[3][i]-1==d[1][b])
det_t=max(det_t,d[1][i]);
}
// cout<<det_s<<' '<<det_t<<"p\n";
//cout<<d[0][a]<<' '<<d[1][a]<<'\n';
//cout<<d[0][b]<<' '<<d[1][b]<<'\n';
ans=min(d[1][a]-d[0][a]-(d[0][a]==d[0][b]),d[1][b]-d[0][b]-(d[0][b]==d[0][a]));
if(ans<0) ans=-1;
cout<<ans;
return 0;
}
Compilation message
007.cpp: In function 'void bfs(int, int)':
007.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Partially correct |
6 ms |
5120 KB |
Partially correct |
4 |
Correct |
7 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Partially correct |
7 ms |
5120 KB |
Partially correct |
7 |
Partially correct |
6 ms |
4992 KB |
Partially correct |
8 |
Correct |
8 ms |
5120 KB |
Output is correct |
9 |
Partially correct |
7 ms |
4992 KB |
Partially correct |
10 |
Correct |
9 ms |
4992 KB |
Output is correct |
11 |
Partially correct |
9 ms |
5120 KB |
Partially correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Partially correct |
7 ms |
5120 KB |
Partially correct |
14 |
Correct |
7 ms |
4988 KB |
Output is correct |
15 |
Partially correct |
7 ms |
5120 KB |
Partially correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
8 ms |
5120 KB |
Output is correct |
18 |
Correct |
7 ms |
5120 KB |
Output is correct |
19 |
Partially correct |
8 ms |
5120 KB |
Partially correct |
20 |
Partially correct |
7 ms |
5120 KB |
Partially correct |
21 |
Correct |
7 ms |
5120 KB |
Output is correct |
22 |
Partially correct |
8 ms |
5120 KB |
Partially correct |
23 |
Partially correct |
7 ms |
5120 KB |
Partially correct |
24 |
Correct |
9 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
60 ms |
7604 KB |
Partially correct |
2 |
Correct |
117 ms |
8696 KB |
Output is correct |
3 |
Partially correct |
85 ms |
7800 KB |
Partially correct |
4 |
Correct |
64 ms |
8952 KB |
Output is correct |
5 |
Correct |
56 ms |
7544 KB |
Output is correct |
6 |
Correct |
61 ms |
7928 KB |
Output is correct |
7 |
Partially correct |
67 ms |
8136 KB |
Partially correct |
8 |
Partially correct |
70 ms |
8056 KB |
Partially correct |
9 |
Correct |
105 ms |
9080 KB |
Output is correct |
10 |
Partially correct |
427 ms |
17724 KB |
Partially correct |
11 |
Correct |
132 ms |
10872 KB |
Output is correct |
12 |
Partially correct |
168 ms |
12392 KB |
Partially correct |
13 |
Correct |
135 ms |
11256 KB |
Output is correct |
14 |
Correct |
116 ms |
10260 KB |
Output is correct |
15 |
Partially correct |
206 ms |
12412 KB |
Partially correct |
16 |
Correct |
171 ms |
12792 KB |
Output is correct |
17 |
Partially correct |
170 ms |
11988 KB |
Partially correct |
18 |
Correct |
149 ms |
11896 KB |
Output is correct |
19 |
Partially correct |
238 ms |
14328 KB |
Partially correct |
20 |
Correct |
487 ms |
20444 KB |
Output is correct |
21 |
Correct |
215 ms |
15224 KB |
Output is correct |
22 |
Partially correct |
192 ms |
13920 KB |
Partially correct |
23 |
Correct |
314 ms |
15096 KB |
Output is correct |
24 |
Partially correct |
230 ms |
14968 KB |
Partially correct |
25 |
Correct |
209 ms |
14456 KB |
Output is correct |
26 |
Correct |
170 ms |
14052 KB |
Output is correct |
27 |
Partially correct |
243 ms |
15224 KB |
Partially correct |
28 |
Partially correct |
231 ms |
15196 KB |
Partially correct |
29 |
Partially correct |
339 ms |
16888 KB |
Partially correct |
30 |
Correct |
468 ms |
21572 KB |
Output is correct |
31 |
Correct |
228 ms |
16888 KB |
Output is correct |
32 |
Partially correct |
241 ms |
15224 KB |
Partially correct |
33 |
Correct |
248 ms |
15724 KB |
Output is correct |
34 |
Correct |
265 ms |
15996 KB |
Output is correct |
35 |
Correct |
248 ms |
15608 KB |
Output is correct |
36 |
Correct |
206 ms |
15992 KB |
Output is correct |
37 |
Correct |
244 ms |
17400 KB |
Output is correct |
38 |
Partially correct |
366 ms |
17160 KB |
Partially correct |
39 |
Partially correct |
333 ms |
17272 KB |
Partially correct |
40 |
Correct |
404 ms |
20816 KB |
Output is correct |
41 |
Partially correct |
702 ms |
25720 KB |
Partially correct |