# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712932 |
2023-03-20T13:36:56 Z |
yuseok0803 |
007 (CEOI14_007) |
C++14 |
|
1000 ms |
524288 KB |
#include <stdio.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <ctype.h>
#define p(x,y) pair<x, y>
#define pii pair<int, int>
#define v(x) vector<x>
#define q(x) queue<x>
#define pq(x) priority_queue<x>
#define uppq(x, comp) priority_queue<x, vector<x>, comp>
#define st(x) set<x>
#define m(x, y) map<x, y>
#define fi(s,e) for(int i=s;i<e;i++)
#define fj(s,e) for(int j=s;j<e;j++)
#define fk(s,e) for(int k=s;k<e;k++)
typedef long long int ll;
typedef unsigned long long int ull;
typedef __int128 ulll;
using namespace std;
int n,m;
int s,d,a,b;
v(int) pushvec;
v(v(int)) vec;
int dista[200010], distb[200010];
int dpdiv[200010];
void spreada(int x){
q(p(pii, int)) qu;
qu.push({{x,x}, 0});
while(!qu.empty()){
p(pii, int) now = qu.front();
qu.pop();
if(now.second > dista[now.first.first] && dista[now.first.first] != -1) continue;
dista[now.first.first]=now.second;
int sz = vec[now.first.first].size();
fi(0,sz){
int next = vec[now.first.first][i];
if(next == now.first.second || (dista[next]!=-1 && dista[next] < now.second+1)) continue;
qu.push({{next, now.first.first}, now.second+1});
}
}
return;
}
void spreadb(int x){
q(p(pii, int)) qu;
qu.push({{x,x}, 0});
while(!qu.empty()){
p(pii, int) now = qu.front();
qu.pop();
if(now.second > distb[now.first.first] && distb[now.first.first] != -1) continue;
distb[now.first.first]=now.second;
int sz = vec[now.first.first].size();
fi(0,sz){
int next = vec[now.first.first][i];
if(next == now.first.second && (distb[next]!=-1 && distb[next] < now.second+1)) continue;
qu.push({{next, now.first.first}, now.second+1});
}
}
return;
}
int find(int now){
if(dpdiv[now]) return dpdiv[now];
int sz = vec[now].size();
int ans = dista[now];
fi(0,sz){
int next = vec[now][i];
if(dista[next]==dista[now]-1 && dista[next]==distb[next]){
ans = min(ans, find(next));
}
}
return dpdiv[now]=ans;
}
int main(void){
scanf("%d%d%d%d%d%d",&n,&m,&s,&d,&a,&b);
fi(0,n+1) vec.push_back(pushvec);
fi(0,m){
int s,e;
scanf("%d%d",&s,&e);
vec[s].push_back(e);
vec[e].push_back(s);
}
fi(1,n+1){
dista[i]=-1;
distb[i]=-1;
}
spreada(a);
spreadb(b);
int ans = min(dista[d]-dista[s], distb[d]-distb[s]);
if(dista[s]==distb[s] && distb[d]==distb[d]){
int divds, divdd;
divds = find(s);
divdd = find(d);
if(divds > divdd) ans--;
}
printf("%d\n", max(ans, -1));
return 0;
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:108:35: warning: self-comparison always evaluates to true [-Wtautological-compare]
108 | if(dista[s]==distb[s] && distb[d]==distb[d]){
| ~~~~~~~~^~~~~~~~~~
007.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%d%d%d%d%d%d",&n,&m,&s,&d,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | scanf("%d%d",&s,&e);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
216 KB |
Output is correct |
15 |
Correct |
1 ms |
224 KB |
Output is correct |
16 |
Correct |
338 ms |
78704 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Execution timed out |
1109 ms |
337840 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3132 KB |
Output is correct |
2 |
Correct |
24 ms |
4704 KB |
Output is correct |
3 |
Correct |
19 ms |
3384 KB |
Output is correct |
4 |
Correct |
24 ms |
4852 KB |
Output is correct |
5 |
Correct |
20 ms |
2940 KB |
Output is correct |
6 |
Correct |
19 ms |
3264 KB |
Output is correct |
7 |
Correct |
20 ms |
3696 KB |
Output is correct |
8 |
Correct |
20 ms |
3744 KB |
Output is correct |
9 |
Execution timed out |
1106 ms |
340992 KB |
Time limit exceeded |
10 |
Execution timed out |
1002 ms |
524288 KB |
Time limit exceeded |
11 |
Correct |
46 ms |
6328 KB |
Output is correct |
12 |
Correct |
64 ms |
7752 KB |
Output is correct |
13 |
Correct |
51 ms |
6684 KB |
Output is correct |
14 |
Correct |
39 ms |
5856 KB |
Output is correct |
15 |
Correct |
55 ms |
8040 KB |
Output is correct |
16 |
Correct |
64 ms |
7952 KB |
Output is correct |
17 |
Correct |
48 ms |
7092 KB |
Output is correct |
18 |
Correct |
51 ms |
7220 KB |
Output is correct |
19 |
Execution timed out |
1105 ms |
350924 KB |
Time limit exceeded |
20 |
Execution timed out |
1105 ms |
416748 KB |
Time limit exceeded |
21 |
Correct |
78 ms |
11528 KB |
Output is correct |
22 |
Correct |
70 ms |
9532 KB |
Output is correct |
23 |
Correct |
88 ms |
10196 KB |
Output is correct |
24 |
Correct |
78 ms |
11076 KB |
Output is correct |
25 |
Correct |
80 ms |
10128 KB |
Output is correct |
26 |
Correct |
66 ms |
9104 KB |
Output is correct |
27 |
Correct |
80 ms |
10284 KB |
Output is correct |
28 |
Correct |
84 ms |
10492 KB |
Output is correct |
29 |
Execution timed out |
1111 ms |
372916 KB |
Time limit exceeded |
30 |
Execution timed out |
1103 ms |
407560 KB |
Time limit exceeded |
31 |
Correct |
106 ms |
13228 KB |
Output is correct |
32 |
Correct |
93 ms |
10792 KB |
Output is correct |
33 |
Correct |
96 ms |
10496 KB |
Output is correct |
34 |
Correct |
102 ms |
11692 KB |
Output is correct |
35 |
Correct |
91 ms |
11976 KB |
Output is correct |
36 |
Correct |
98 ms |
12460 KB |
Output is correct |
37 |
Correct |
119 ms |
12364 KB |
Output is correct |
38 |
Correct |
99 ms |
12216 KB |
Output is correct |
39 |
Correct |
113 ms |
12244 KB |
Output is correct |
40 |
Execution timed out |
1098 ms |
328848 KB |
Time limit exceeded |
41 |
Execution timed out |
1096 ms |
365264 KB |
Time limit exceeded |