#include<bits/stdc++.h>
using namespace std;
int n , m , is [502] , st [502] , fn [502] , ff;
vector < int > gr [502] , v , pth;
void go ( int x , int p , int pr )
{
pth . push_back ( x );
if ( fn [pr] == x )
{
for ( auto u : pth )
{
if ( is [u] == 1 && u != st [pr] ) ff = 1;
}
is [ st [pr] ] = 0;
is [ fn [pr] ] = 1;
}
for ( auto u : gr [x] )
{
if ( u == p ) continue;
go ( u , x , pr );
}
pth . pop_back ();
}
bool ck ( )
{
ff = 0;
for ( int i = 1 ; i <= n ; i ++ ) is [i] = 0;
for ( int i = 1 ; i <= m ; i ++ ) is [ st [i] ] = 1;
for ( auto x : v )
{
go ( st [x] , 0 , x );
}
if ( ff ) return 0;
return 1;
}
int main()
{
int q;
cin >> q;
while ( q -- )
{
cin >> n;
for ( int i = 1 ; i <= n ; i ++ )
{
gr [i] . clear ();
is [i] = 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 );
}
cin >> m;
v . clear ();
for ( int i = 1 ; i <= m ; i ++ )
{
v . push_back ( i );
cin >> st [i] >> fn [i];
}
int f = 0;
do
{
f = max ( f , ( int ) ck () );
} while ( next_permutation( v . begin () , v . end () ) );
if ( f ) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
30 ms |
568 KB |
Output is correct |
5 |
Correct |
63 ms |
948 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
223 ms |
372 KB |
Output is correct |
8 |
Execution timed out |
5031 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
260 ms |
360 KB |
Output is correct |
17 |
Correct |
63 ms |
340 KB |
Output is correct |
18 |
Correct |
195 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
195 ms |
340 KB |
Output is correct |
21 |
Correct |
199 ms |
364 KB |
Output is correct |
22 |
Correct |
158 ms |
356 KB |
Output is correct |
23 |
Correct |
10 ms |
212 KB |
Output is correct |
24 |
Correct |
12 ms |
336 KB |
Output is correct |
25 |
Correct |
230 ms |
352 KB |
Output is correct |
26 |
Correct |
36 ms |
328 KB |
Output is correct |
27 |
Correct |
163 ms |
340 KB |
Output is correct |
28 |
Correct |
17 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
260 ms |
360 KB |
Output is correct |
17 |
Correct |
63 ms |
340 KB |
Output is correct |
18 |
Correct |
195 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
195 ms |
340 KB |
Output is correct |
21 |
Correct |
199 ms |
364 KB |
Output is correct |
22 |
Correct |
158 ms |
356 KB |
Output is correct |
23 |
Correct |
10 ms |
212 KB |
Output is correct |
24 |
Correct |
12 ms |
336 KB |
Output is correct |
25 |
Correct |
230 ms |
352 KB |
Output is correct |
26 |
Correct |
36 ms |
328 KB |
Output is correct |
27 |
Correct |
163 ms |
340 KB |
Output is correct |
28 |
Correct |
17 ms |
324 KB |
Output is correct |
29 |
Execution timed out |
5093 ms |
336 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
260 ms |
360 KB |
Output is correct |
17 |
Correct |
63 ms |
340 KB |
Output is correct |
18 |
Correct |
195 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
195 ms |
340 KB |
Output is correct |
21 |
Correct |
199 ms |
364 KB |
Output is correct |
22 |
Correct |
158 ms |
356 KB |
Output is correct |
23 |
Correct |
10 ms |
212 KB |
Output is correct |
24 |
Correct |
12 ms |
336 KB |
Output is correct |
25 |
Correct |
230 ms |
352 KB |
Output is correct |
26 |
Correct |
36 ms |
328 KB |
Output is correct |
27 |
Correct |
163 ms |
340 KB |
Output is correct |
28 |
Correct |
17 ms |
324 KB |
Output is correct |
29 |
Execution timed out |
5093 ms |
336 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 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 |
328 KB |
Output is correct |
5 |
Execution timed out |
5017 ms |
328 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
30 ms |
568 KB |
Output is correct |
5 |
Correct |
63 ms |
948 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
223 ms |
372 KB |
Output is correct |
8 |
Execution timed out |
5031 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |