This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |