# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631775 |
2022-08-18T17:27:43 Z |
mdn2002 |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
434352 KB |
#include<bits/stdc++.h>
using namespace std;
int n , m , st [200005][21] , dp [200005] , s [200005] , t [200005] , aaa [200005] , vis [200005] , ff;
vector < int > gr [200005] , grr [200005] , ss [200005] , tt [200005];
void dfs ( int x , int p )
{
dp [x] = dp [p] + 1;
st [x][0] = p;
for ( auto u : gr [x] )
{
if ( u == p ) continue;
dfs ( u , x );
}
}
void go ( int x , int p )
{
aaa [x] = aaa [p];
if ( ss [x] . size () || tt [x] . size () ) aaa [x] = x;
for ( auto u : gr [x] )
{
if ( u == p ) continue;
go ( u , x );
}
}
void dfss ( int x )
{
vis [x] = 1;
for ( auto u : grr [x] )
{
if ( vis [u] == 1 )
{
ff = 1;
continue;
}
else if ( vis [u] == 2 ) continue;
else dfss ( u );
}
vis [x] = 2;
}
int lca ( int x , int y )
{
if ( dp [x] > dp [y] ) swap ( x , y );
int dif = dp [y] - dp [x];
for ( int i = 0 ; i <= 20 ; i ++ )
{
if ( ( dif & ( 1 << i ) ) ) y = st [y][i];
}
if ( x == y ) return x;
for ( int i = 20 ; i >= 0 ; i -- )
{
if ( st [x][i] != st [y][i] )
{
x = st [x][i];
y = st [y][i];
}
}
return st [x][0];
}
int inbet ( int x , int y , int z )
{
if ( dp [z] > dp [x] && dp [z] > dp [y] ) return 0;
int aa = lca ( x , y );
if ( dp [aa] > dp [z] ) return 0;
int a = lca ( x , z );
int b = lca ( y , z );
if ( a == z || b == z ) return 1;
return 0;
}
int main()
{
int q;
cin >> q;
while ( q -- )
{
ff = 0;
cin >> n;
for ( int i = 1 ; i <= n ; i ++ )
{
gr [i] . clear ();
grr [i] . clear ();
ss [i] . clear ();
tt [i] . clear ();
dp [i] = 0;
vis [i] = 0;
aaa [i] = 0;
for ( int j = 0 ; j <= 20 ; j ++ ) st [i][j] = 0;
}
for ( int i = 0 ; i < n - 1 ; i ++ )
{
int x , y;
cin >> x >> y;
gr [x] . push_back ( y );
gr [y] . push_back ( x );
}
dfs ( 1 , 0 );
for ( int i = 1 ; i <= 20 ; i ++ )
{
for ( int j = 1 ; j <= n ; j ++ ) st [j][i] = st [ st [j][ i - 1 ] ][ i - 1 ];
}
cin >> m;
long long sum = 0;
for ( int i = 1 ; i <= m ; i ++ )
{
cin >> s [i] >> t [i];
ss [ s [i] ] . push_back ( i );
tt [ t [i] ] . push_back ( i );
int a = lca ( s [i] , t [i] );
}
go ( 1 , 0 );
int num = 0;
for ( int i = 1 ; i <= m ; i ++ )
{
int x = s [i] , y = t [i] , z = lca ( x , y );
while ( true )
{
if ( dp [x] < dp [z] ) break;
if ( ss [x] . size () )
{
if ( ss [x][0] != i )
{
grr [i] . push_back ( ss [x][0] );
num ++;
}
}
if ( tt [x] . size () )
{
if ( tt [x][0] != i )
{
grr [ tt [x][0] ] . push_back ( i );
num ++;
}
}
//if ( num > 5 * m ) break;
if ( x == z ) break;
x = aaa [ st [x][0] ];
}
x = t [i];
while ( true )
{
if ( dp [x] < dp [z] ) break;
if ( ss [x] . size () )
{
if ( ss [x][0] != i )
{
grr [i] . push_back ( ss [x][0] );
num ++;
}
}
if ( tt [x] . size () )
{
if ( tt [x][0] != i )
{
grr [ tt [x][0] ] . push_back ( i );
num ++;
}
}
//if ( num > 6 * m ) break;
if ( x == z ) break;
x = aaa [ st [x][0] ];
}
}
for ( int i = 1 ; i <= m ; i ++ )
{
if ( vis [i] == 0 ) dfss ( i );
}
if ( ff ) cout << "No" << endl;
else cout << "Yes" << endl;
}
}
/*
1
4
1 2
2 3
3 4
2
1 3
4 2
*/
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:107:17: warning: unused variable 'a' [-Wunused-variable]
107 | int a = lca ( s [i] , t [i] );
| ^
jail.cpp:101:19: warning: unused variable 'sum' [-Wunused-variable]
101 | long long sum = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
9 ms |
19028 KB |
Output is correct |
4 |
Correct |
33 ms |
19144 KB |
Output is correct |
5 |
Correct |
61 ms |
19028 KB |
Output is correct |
6 |
Correct |
12 ms |
19156 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
16 ms |
19252 KB |
Output is correct |
9 |
Correct |
105 ms |
22216 KB |
Output is correct |
10 |
Correct |
115 ms |
41156 KB |
Output is correct |
11 |
Correct |
21 ms |
19028 KB |
Output is correct |
12 |
Correct |
85 ms |
19276 KB |
Output is correct |
13 |
Correct |
237 ms |
72908 KB |
Output is correct |
14 |
Correct |
266 ms |
86868 KB |
Output is correct |
15 |
Execution timed out |
5071 ms |
434352 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19188 KB |
Output is correct |
6 |
Correct |
13 ms |
19104 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19108 KB |
Output is correct |
9 |
Correct |
12 ms |
19120 KB |
Output is correct |
10 |
Correct |
12 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
13 ms |
19156 KB |
Output is correct |
13 |
Correct |
11 ms |
19164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19188 KB |
Output is correct |
6 |
Correct |
13 ms |
19104 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19108 KB |
Output is correct |
9 |
Correct |
12 ms |
19120 KB |
Output is correct |
10 |
Correct |
12 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
13 ms |
19156 KB |
Output is correct |
13 |
Correct |
11 ms |
19164 KB |
Output is correct |
14 |
Correct |
10 ms |
19028 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
12 ms |
19100 KB |
Output is correct |
17 |
Correct |
12 ms |
19156 KB |
Output is correct |
18 |
Correct |
12 ms |
19156 KB |
Output is correct |
19 |
Correct |
12 ms |
19028 KB |
Output is correct |
20 |
Correct |
16 ms |
19156 KB |
Output is correct |
21 |
Correct |
12 ms |
19104 KB |
Output is correct |
22 |
Correct |
13 ms |
19196 KB |
Output is correct |
23 |
Correct |
10 ms |
19028 KB |
Output is correct |
24 |
Correct |
11 ms |
19120 KB |
Output is correct |
25 |
Correct |
13 ms |
19172 KB |
Output is correct |
26 |
Correct |
11 ms |
19156 KB |
Output is correct |
27 |
Correct |
12 ms |
19132 KB |
Output is correct |
28 |
Correct |
11 ms |
19028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19188 KB |
Output is correct |
6 |
Correct |
13 ms |
19104 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19108 KB |
Output is correct |
9 |
Correct |
12 ms |
19120 KB |
Output is correct |
10 |
Correct |
12 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
13 ms |
19156 KB |
Output is correct |
13 |
Correct |
11 ms |
19164 KB |
Output is correct |
14 |
Correct |
10 ms |
19028 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
12 ms |
19100 KB |
Output is correct |
17 |
Correct |
12 ms |
19156 KB |
Output is correct |
18 |
Correct |
12 ms |
19156 KB |
Output is correct |
19 |
Correct |
12 ms |
19028 KB |
Output is correct |
20 |
Correct |
16 ms |
19156 KB |
Output is correct |
21 |
Correct |
12 ms |
19104 KB |
Output is correct |
22 |
Correct |
13 ms |
19196 KB |
Output is correct |
23 |
Correct |
10 ms |
19028 KB |
Output is correct |
24 |
Correct |
11 ms |
19120 KB |
Output is correct |
25 |
Correct |
13 ms |
19172 KB |
Output is correct |
26 |
Correct |
11 ms |
19156 KB |
Output is correct |
27 |
Correct |
12 ms |
19132 KB |
Output is correct |
28 |
Correct |
11 ms |
19028 KB |
Output is correct |
29 |
Correct |
14 ms |
19284 KB |
Output is correct |
30 |
Correct |
17 ms |
19108 KB |
Output is correct |
31 |
Correct |
15 ms |
19204 KB |
Output is correct |
32 |
Correct |
14 ms |
19188 KB |
Output is correct |
33 |
Correct |
13 ms |
19168 KB |
Output is correct |
34 |
Correct |
14 ms |
19104 KB |
Output is correct |
35 |
Correct |
14 ms |
19236 KB |
Output is correct |
36 |
Correct |
12 ms |
19156 KB |
Output is correct |
37 |
Correct |
12 ms |
19104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19188 KB |
Output is correct |
6 |
Correct |
13 ms |
19104 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19108 KB |
Output is correct |
9 |
Correct |
12 ms |
19120 KB |
Output is correct |
10 |
Correct |
12 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
13 ms |
19156 KB |
Output is correct |
13 |
Correct |
11 ms |
19164 KB |
Output is correct |
14 |
Correct |
10 ms |
19028 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
12 ms |
19100 KB |
Output is correct |
17 |
Correct |
12 ms |
19156 KB |
Output is correct |
18 |
Correct |
12 ms |
19156 KB |
Output is correct |
19 |
Correct |
12 ms |
19028 KB |
Output is correct |
20 |
Correct |
16 ms |
19156 KB |
Output is correct |
21 |
Correct |
12 ms |
19104 KB |
Output is correct |
22 |
Correct |
13 ms |
19196 KB |
Output is correct |
23 |
Correct |
10 ms |
19028 KB |
Output is correct |
24 |
Correct |
11 ms |
19120 KB |
Output is correct |
25 |
Correct |
13 ms |
19172 KB |
Output is correct |
26 |
Correct |
11 ms |
19156 KB |
Output is correct |
27 |
Correct |
12 ms |
19132 KB |
Output is correct |
28 |
Correct |
11 ms |
19028 KB |
Output is correct |
29 |
Correct |
14 ms |
19284 KB |
Output is correct |
30 |
Correct |
17 ms |
19108 KB |
Output is correct |
31 |
Correct |
15 ms |
19204 KB |
Output is correct |
32 |
Correct |
14 ms |
19188 KB |
Output is correct |
33 |
Correct |
13 ms |
19168 KB |
Output is correct |
34 |
Correct |
14 ms |
19104 KB |
Output is correct |
35 |
Correct |
14 ms |
19236 KB |
Output is correct |
36 |
Correct |
12 ms |
19156 KB |
Output is correct |
37 |
Correct |
12 ms |
19104 KB |
Output is correct |
38 |
Correct |
108 ms |
23536 KB |
Output is correct |
39 |
Correct |
114 ms |
42660 KB |
Output is correct |
40 |
Correct |
96 ms |
22560 KB |
Output is correct |
41 |
Correct |
78 ms |
21368 KB |
Output is correct |
42 |
Correct |
86 ms |
22600 KB |
Output is correct |
43 |
Correct |
73 ms |
21140 KB |
Output is correct |
44 |
Correct |
29 ms |
19612 KB |
Output is correct |
45 |
Correct |
132 ms |
35636 KB |
Output is correct |
46 |
Correct |
130 ms |
35636 KB |
Output is correct |
47 |
Correct |
110 ms |
38348 KB |
Output is correct |
48 |
Correct |
111 ms |
38348 KB |
Output is correct |
49 |
Correct |
121 ms |
35916 KB |
Output is correct |
50 |
Correct |
136 ms |
35732 KB |
Output is correct |
51 |
Correct |
109 ms |
36480 KB |
Output is correct |
52 |
Correct |
109 ms |
36532 KB |
Output is correct |
53 |
Correct |
30 ms |
20564 KB |
Output is correct |
54 |
Correct |
143 ms |
35492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19028 KB |
Output is correct |
2 |
Correct |
12 ms |
19092 KB |
Output is correct |
3 |
Correct |
12 ms |
19052 KB |
Output is correct |
4 |
Correct |
10 ms |
19028 KB |
Output is correct |
5 |
Correct |
24 ms |
19240 KB |
Output is correct |
6 |
Correct |
11 ms |
19128 KB |
Output is correct |
7 |
Correct |
12 ms |
19128 KB |
Output is correct |
8 |
Correct |
10 ms |
19028 KB |
Output is correct |
9 |
Correct |
10 ms |
19096 KB |
Output is correct |
10 |
Correct |
11 ms |
19028 KB |
Output is correct |
11 |
Correct |
11 ms |
19064 KB |
Output is correct |
12 |
Correct |
13 ms |
19104 KB |
Output is correct |
13 |
Correct |
51 ms |
19276 KB |
Output is correct |
14 |
Correct |
72 ms |
19376 KB |
Output is correct |
15 |
Correct |
60 ms |
19324 KB |
Output is correct |
16 |
Correct |
142 ms |
36788 KB |
Output is correct |
17 |
Correct |
302 ms |
46900 KB |
Output is correct |
18 |
Correct |
675 ms |
74888 KB |
Output is correct |
19 |
Correct |
152 ms |
37700 KB |
Output is correct |
20 |
Correct |
147 ms |
37660 KB |
Output is correct |
21 |
Correct |
146 ms |
37512 KB |
Output is correct |
22 |
Correct |
309 ms |
47304 KB |
Output is correct |
23 |
Correct |
229 ms |
47100 KB |
Output is correct |
24 |
Correct |
231 ms |
47048 KB |
Output is correct |
25 |
Correct |
229 ms |
47388 KB |
Output is correct |
26 |
Correct |
246 ms |
47232 KB |
Output is correct |
27 |
Correct |
337 ms |
53820 KB |
Output is correct |
28 |
Correct |
343 ms |
55272 KB |
Output is correct |
29 |
Correct |
329 ms |
52396 KB |
Output is correct |
30 |
Correct |
225 ms |
44872 KB |
Output is correct |
31 |
Correct |
229 ms |
45400 KB |
Output is correct |
32 |
Correct |
215 ms |
44676 KB |
Output is correct |
33 |
Correct |
210 ms |
45384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
9 ms |
19028 KB |
Output is correct |
4 |
Correct |
33 ms |
19144 KB |
Output is correct |
5 |
Correct |
61 ms |
19028 KB |
Output is correct |
6 |
Correct |
12 ms |
19156 KB |
Output is correct |
7 |
Correct |
12 ms |
19156 KB |
Output is correct |
8 |
Correct |
16 ms |
19252 KB |
Output is correct |
9 |
Correct |
105 ms |
22216 KB |
Output is correct |
10 |
Correct |
115 ms |
41156 KB |
Output is correct |
11 |
Correct |
21 ms |
19028 KB |
Output is correct |
12 |
Correct |
85 ms |
19276 KB |
Output is correct |
13 |
Correct |
237 ms |
72908 KB |
Output is correct |
14 |
Correct |
266 ms |
86868 KB |
Output is correct |
15 |
Execution timed out |
5071 ms |
434352 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |