# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
475256 |
2021-09-21T16:56:23 Z |
MohamedAhmed04 |
007 (CEOI14_007) |
C++14 |
|
242 ms |
23404 KB |
#include <bits/stdc++.h>
using namespace std ;
const int inf = 1e9 ;
const int MAX = 2e5 + 10 ;
int arr[MAX] ;
int n , m ;
int a , b , x , y ;
vector< vector<int> >adj(MAX) ;
int dist[2][MAX] ;
void bfs(int src , int t)
{
for(int i = 1 ; i <= n ; ++i)
dist[t][i] = inf ;
queue<int>q ;
dist[t][src] = 0 ;
q.push(src) ;
while(!q.empty())
{
int node = q.front() ;
q.pop() ;
for(auto &child : adj[node])
{
if(dist[t][node]+1 < dist[t][child])
{
dist[t][child] = dist[t][node]+1 ;
q.push(child) ;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
cin>>a>>b>>x>>y ;
for(int i = 0 ; i < m ; ++i)
{
int u , v ;
cin>>u>>v ;
adj[u].push_back(v) ;
adj[v].push_back(u) ;
}
bfs(a , 0) ;
bfs(b , 1) ;
return cout<<max(-1 , min(dist[1][x] - dist[0][x] , dist[1][y] - dist[0][y]))<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5036 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
5036 KB |
Output isn't correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
3 ms |
5036 KB |
Output isn't correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Incorrect |
3 ms |
5032 KB |
Output isn't correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Incorrect |
3 ms |
5068 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
5040 KB |
Output isn't correct |
19 |
Correct |
3 ms |
5004 KB |
Output is correct |
20 |
Correct |
4 ms |
5044 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
3 ms |
5028 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
7008 KB |
Output is correct |
2 |
Incorrect |
29 ms |
8040 KB |
Output isn't correct |
3 |
Correct |
24 ms |
7244 KB |
Output is correct |
4 |
Incorrect |
30 ms |
8108 KB |
Output isn't correct |
5 |
Correct |
21 ms |
6980 KB |
Output is correct |
6 |
Correct |
22 ms |
7256 KB |
Output is correct |
7 |
Correct |
26 ms |
7480 KB |
Output is correct |
8 |
Correct |
28 ms |
7504 KB |
Output is correct |
9 |
Incorrect |
37 ms |
8280 KB |
Output isn't correct |
10 |
Correct |
140 ms |
16808 KB |
Output is correct |
11 |
Incorrect |
51 ms |
9648 KB |
Output isn't correct |
12 |
Correct |
66 ms |
10876 KB |
Output is correct |
13 |
Incorrect |
56 ms |
10028 KB |
Output isn't correct |
14 |
Correct |
41 ms |
9208 KB |
Output is correct |
15 |
Correct |
59 ms |
10916 KB |
Output is correct |
16 |
Correct |
65 ms |
11276 KB |
Output is correct |
17 |
Correct |
56 ms |
10472 KB |
Output is correct |
18 |
Incorrect |
66 ms |
10564 KB |
Output isn't correct |
19 |
Correct |
90 ms |
12996 KB |
Output is correct |
20 |
Incorrect |
180 ms |
18744 KB |
Output isn't correct |
21 |
Incorrect |
88 ms |
13184 KB |
Output isn't correct |
22 |
Correct |
78 ms |
12136 KB |
Output is correct |
23 |
Correct |
88 ms |
13036 KB |
Output is correct |
24 |
Correct |
88 ms |
12996 KB |
Output is correct |
25 |
Incorrect |
84 ms |
12592 KB |
Output isn't correct |
26 |
Correct |
87 ms |
12216 KB |
Output is correct |
27 |
Correct |
89 ms |
13180 KB |
Output is correct |
28 |
Correct |
111 ms |
13236 KB |
Output is correct |
29 |
Correct |
129 ms |
15148 KB |
Output is correct |
30 |
Incorrect |
184 ms |
19780 KB |
Output isn't correct |
31 |
Incorrect |
120 ms |
14552 KB |
Output isn't correct |
32 |
Correct |
97 ms |
13252 KB |
Output is correct |
33 |
Correct |
93 ms |
13380 KB |
Output is correct |
34 |
Incorrect |
120 ms |
13852 KB |
Output isn't correct |
35 |
Incorrect |
88 ms |
13528 KB |
Output isn't correct |
36 |
Incorrect |
91 ms |
13784 KB |
Output isn't correct |
37 |
Correct |
121 ms |
15024 KB |
Output is correct |
38 |
Correct |
116 ms |
14828 KB |
Output is correct |
39 |
Correct |
118 ms |
14788 KB |
Output is correct |
40 |
Incorrect |
169 ms |
18608 KB |
Output isn't correct |
41 |
Correct |
242 ms |
23404 KB |
Output is correct |