# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
450122 |
2021-08-02T11:33:12 Z |
vanic |
007 (CEOI14_007) |
C++14 |
|
344 ms |
17096 KB |
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=2e5+5;
vector < int > ms[maxn];
int dist[2][maxn];
bool bio[2][2][maxn];
void bfs(int x, int ind){
queue < int > q;
q.push(x);
dist[ind][x]=0;
while(!q.empty()){
x=q.front();
q.pop();
for(int i=0; i<(int)ms[x].size(); i++){
if(dist[ind][ms[x][i]]==-1){
dist[ind][ms[x][i]]=dist[ind][x]+1;
q.push(ms[x][i]);
}
}
}
}
void siri(int x, int y, int z){
bio[y][z][x]=1;
for(int i=0; i<(int)ms[x].size(); i++){
if(!bio[y][z][ms[x][i]] && dist[y][ms[x][i]]==dist[y][x]-1){
siri(ms[x][i], y, z);
}
}
}
int main(){
memset(dist, -1, sizeof(dist));
int n, m;
scanf("%d%d", &n, &m);
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
a--; b--; c--; d--;
int x, y;
for(int i=0; i<m; i++){
scanf("%d%d", &x, &y);
x--; y--;
ms[x].push_back(y);
ms[y].push_back(x);
}
bfs(a, 0);
bfs(b, 1);
if(dist[0][c]>dist[1][c] || dist[0][d]>dist[1][d]){
printf("-1\n");
}
else{
if(dist[0][c]-dist[1][c]==dist[0][d]-dist[1][d]){
siri(c, 0, 0);
siri(d, 0, 1);
siri(c, 1, 0);
siri(d, 1, 1);
int mini[2]={(int)1e9, (int)1e9};
int cvor[2];
int val;
for(int j=0; j<2; j++){
for(int i=0; i<n; i++){
if(bio[j][0][i] && bio[j][1][i]){
val=dist[j][c]-dist[j][i];
if(val<mini[j]){
mini[j]=val;
cvor[j]=i;
}
}
}
}
int raz=dist[1][c]-dist[0][c];
if(cvor[0]==cvor[1]){
printf("%d\n", raz);
}
else{
if(mini[0]<=mini[1]){
printf("%d\n", raz);
}
else{
printf("%d\n", raz-1);
}
}
}
else{
printf("%d\n", min(dist[1][c]-dist[0][c], dist[1][d]-dist[0][d]));
}
}
return 0;
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
007.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d%d%d%d", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
4 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6476 KB |
Output is correct |
4 |
Correct |
4 ms |
6476 KB |
Output is correct |
5 |
Correct |
5 ms |
6464 KB |
Output is correct |
6 |
Correct |
4 ms |
6476 KB |
Output is correct |
7 |
Correct |
4 ms |
6476 KB |
Output is correct |
8 |
Correct |
4 ms |
6476 KB |
Output is correct |
9 |
Correct |
4 ms |
6476 KB |
Output is correct |
10 |
Correct |
4 ms |
6476 KB |
Output is correct |
11 |
Correct |
4 ms |
6476 KB |
Output is correct |
12 |
Correct |
4 ms |
6476 KB |
Output is correct |
13 |
Correct |
4 ms |
6476 KB |
Output is correct |
14 |
Correct |
5 ms |
6476 KB |
Output is correct |
15 |
Correct |
4 ms |
6476 KB |
Output is correct |
16 |
Correct |
4 ms |
6476 KB |
Output is correct |
17 |
Correct |
4 ms |
6476 KB |
Output is correct |
18 |
Correct |
4 ms |
6476 KB |
Output is correct |
19 |
Correct |
4 ms |
6476 KB |
Output is correct |
20 |
Correct |
4 ms |
6476 KB |
Output is correct |
21 |
Correct |
6 ms |
6472 KB |
Output is correct |
22 |
Correct |
4 ms |
6476 KB |
Output is correct |
23 |
Correct |
4 ms |
6476 KB |
Output is correct |
24 |
Correct |
4 ms |
6476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
7948 KB |
Output is correct |
2 |
Correct |
34 ms |
9092 KB |
Output is correct |
3 |
Correct |
34 ms |
8060 KB |
Output is correct |
4 |
Correct |
35 ms |
9072 KB |
Output is correct |
5 |
Correct |
25 ms |
7764 KB |
Output is correct |
6 |
Correct |
24 ms |
7948 KB |
Output is correct |
7 |
Correct |
28 ms |
8288 KB |
Output is correct |
8 |
Correct |
33 ms |
8188 KB |
Output is correct |
9 |
Correct |
50 ms |
8724 KB |
Output is correct |
10 |
Correct |
189 ms |
12844 KB |
Output is correct |
11 |
Correct |
58 ms |
9796 KB |
Output is correct |
12 |
Correct |
70 ms |
10524 KB |
Output is correct |
13 |
Correct |
63 ms |
9960 KB |
Output is correct |
14 |
Correct |
49 ms |
9116 KB |
Output is correct |
15 |
Correct |
86 ms |
10692 KB |
Output is correct |
16 |
Correct |
88 ms |
10352 KB |
Output is correct |
17 |
Correct |
69 ms |
10460 KB |
Output is correct |
18 |
Correct |
64 ms |
10312 KB |
Output is correct |
19 |
Correct |
112 ms |
11536 KB |
Output is correct |
20 |
Correct |
263 ms |
14300 KB |
Output is correct |
21 |
Correct |
112 ms |
13540 KB |
Output is correct |
22 |
Correct |
87 ms |
11360 KB |
Output is correct |
23 |
Correct |
98 ms |
13300 KB |
Output is correct |
24 |
Correct |
114 ms |
13212 KB |
Output is correct |
25 |
Correct |
101 ms |
11864 KB |
Output is correct |
26 |
Correct |
82 ms |
11608 KB |
Output is correct |
27 |
Correct |
104 ms |
12212 KB |
Output is correct |
28 |
Correct |
140 ms |
12060 KB |
Output is correct |
29 |
Correct |
186 ms |
12892 KB |
Output is correct |
30 |
Correct |
307 ms |
14936 KB |
Output is correct |
31 |
Correct |
151 ms |
14880 KB |
Output is correct |
32 |
Correct |
143 ms |
12120 KB |
Output is correct |
33 |
Correct |
114 ms |
12536 KB |
Output is correct |
34 |
Correct |
116 ms |
12516 KB |
Output is correct |
35 |
Correct |
117 ms |
13764 KB |
Output is correct |
36 |
Correct |
158 ms |
14356 KB |
Output is correct |
37 |
Correct |
143 ms |
12620 KB |
Output is correct |
38 |
Correct |
124 ms |
13248 KB |
Output is correct |
39 |
Correct |
132 ms |
13248 KB |
Output is correct |
40 |
Correct |
234 ms |
14912 KB |
Output is correct |
41 |
Correct |
344 ms |
17096 KB |
Output is correct |