#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define pb push_back
#define mk make_pair
using namespace std;
int n,m,go[120005][22],dep[120005],s[120005],t[120005],dfn[120005],dfo[120005],T;
vector<int> g[120005];
void dfs(int v,int pr)
{
dep[v]=dep[pr]+1;go[v][0]=pr;dfn[v]=++T;
for(int u:g[v])if(u!=pr)dfs(u,v);
dfo[v]=T;
}
bool in(int x,int y){return dfn[x]<=dfn[y]&&dfo[y]<=dfo[x];}
int lca(int u,int v)
{
if(dep[u]<dep[v])swap(u,v);
for(int i=19;i>=0;i--)if(dep[go[u][i]]>=dep[v])u=go[u][i];
assert(u!=0);
if(u==v)return u;
assert(dep[u]==dep[v]);
for(int i=19;i>=0;i--)if(go[u][i]!=go[v][i])u=go[u][i],v=go[v][i];
assert(go[u][0]!=0);
return go[u][0];
}
int deg[120005];vector<int> e[120005];
void init()
{
T=0;
for(int i=1;i<=120000;i++)g[i].clear(),dep[i]=0;
for(int i=1;i<=120000;i++)for(int j=0;j<20;j++)go[i][j]=0;
for(int i=1;i<=120000;i++)deg[i]=0,e[i].clear();
}
void adde(int x,int y){deg[y]++;e[x].pb(y);}
bool on(int x,int y,int z){int l=lca(x,y);return in(l,z)&&(in(z,x)||in(z,y));}
int qu[120005],qsz;
void solve()
{
init();scanf("%d",&n);
for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
dfs(1,0);
for(int j=1;j<20;j++)for(int i=1;i<=n;i++)go[i][j]=go[go[i][j-1]][j-1];
scanf("%d",&m);
for(int i=1;i<=m;i++)scanf("%d%d",&s[i],&t[i]);
for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)if(i!=j&&on(s[i],t[i],s[j]))adde(j,i);
for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)if(i!=j&&on(s[i],t[i],t[j]))adde(i,j);
qsz=0;for(int i=1;i<=m;i++)if(deg[i]==0)qu[++qsz]=i;
for(int i=1;i<=qsz;i++)for(int j:e[qu[i]]){
deg[j]--;
if(deg[j]==0)qu[++qsz]=j;
assert(deg[j]>=0);
}
bool ok=1;for(int i=1;i<=m;i++)ok&=(deg[i]==0);
printf(ok?"Yes\n":"No\n");
}
int main()
{
int t;scanf("%d",&t);
while(t--)solve();
return 0;
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | init();scanf("%d",&n);
| ~~~~~^~~~~~~~~
jail.cpp:53:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
| ~~~~~^~~~~~~~~~~~~~
jail.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
jail.cpp:57:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | for(int i=1;i<=m;i++)scanf("%d%d",&s[i],&t[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:71:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | int t;scanf("%d",&t);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
17236 KB |
Output is correct |
2 |
Correct |
12 ms |
17256 KB |
Output is correct |
3 |
Correct |
9 ms |
17236 KB |
Output is correct |
4 |
Correct |
779 ms |
17236 KB |
Output is correct |
5 |
Correct |
1608 ms |
17232 KB |
Output is correct |
6 |
Correct |
40 ms |
17236 KB |
Output is correct |
7 |
Correct |
40 ms |
17244 KB |
Output is correct |
8 |
Correct |
87 ms |
17304 KB |
Output is correct |
9 |
Correct |
1222 ms |
19776 KB |
Output is correct |
10 |
Correct |
132 ms |
30268 KB |
Output is correct |
11 |
Correct |
1595 ms |
17484 KB |
Output is correct |
12 |
Correct |
2073 ms |
18252 KB |
Output is correct |
13 |
Execution timed out |
5058 ms |
30100 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17224 KB |
Output is correct |
2 |
Correct |
8 ms |
17236 KB |
Output is correct |
3 |
Correct |
39 ms |
17236 KB |
Output is correct |
4 |
Correct |
39 ms |
17236 KB |
Output is correct |
5 |
Correct |
39 ms |
17244 KB |
Output is correct |
6 |
Correct |
39 ms |
17176 KB |
Output is correct |
7 |
Correct |
42 ms |
17236 KB |
Output is correct |
8 |
Correct |
40 ms |
17220 KB |
Output is correct |
9 |
Correct |
43 ms |
17228 KB |
Output is correct |
10 |
Correct |
42 ms |
17236 KB |
Output is correct |
11 |
Correct |
34 ms |
17248 KB |
Output is correct |
12 |
Correct |
39 ms |
17152 KB |
Output is correct |
13 |
Correct |
39 ms |
17236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17224 KB |
Output is correct |
2 |
Correct |
8 ms |
17236 KB |
Output is correct |
3 |
Correct |
39 ms |
17236 KB |
Output is correct |
4 |
Correct |
39 ms |
17236 KB |
Output is correct |
5 |
Correct |
39 ms |
17244 KB |
Output is correct |
6 |
Correct |
39 ms |
17176 KB |
Output is correct |
7 |
Correct |
42 ms |
17236 KB |
Output is correct |
8 |
Correct |
40 ms |
17220 KB |
Output is correct |
9 |
Correct |
43 ms |
17228 KB |
Output is correct |
10 |
Correct |
42 ms |
17236 KB |
Output is correct |
11 |
Correct |
34 ms |
17248 KB |
Output is correct |
12 |
Correct |
39 ms |
17152 KB |
Output is correct |
13 |
Correct |
39 ms |
17236 KB |
Output is correct |
14 |
Correct |
10 ms |
17236 KB |
Output is correct |
15 |
Correct |
12 ms |
17168 KB |
Output is correct |
16 |
Correct |
39 ms |
17240 KB |
Output is correct |
17 |
Correct |
40 ms |
17252 KB |
Output is correct |
18 |
Correct |
40 ms |
17224 KB |
Output is correct |
19 |
Correct |
40 ms |
17216 KB |
Output is correct |
20 |
Correct |
40 ms |
17236 KB |
Output is correct |
21 |
Correct |
39 ms |
17236 KB |
Output is correct |
22 |
Correct |
39 ms |
17236 KB |
Output is correct |
23 |
Correct |
39 ms |
17128 KB |
Output is correct |
24 |
Correct |
39 ms |
17216 KB |
Output is correct |
25 |
Correct |
40 ms |
17228 KB |
Output is correct |
26 |
Correct |
39 ms |
17236 KB |
Output is correct |
27 |
Correct |
40 ms |
17236 KB |
Output is correct |
28 |
Correct |
38 ms |
17228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17224 KB |
Output is correct |
2 |
Correct |
8 ms |
17236 KB |
Output is correct |
3 |
Correct |
39 ms |
17236 KB |
Output is correct |
4 |
Correct |
39 ms |
17236 KB |
Output is correct |
5 |
Correct |
39 ms |
17244 KB |
Output is correct |
6 |
Correct |
39 ms |
17176 KB |
Output is correct |
7 |
Correct |
42 ms |
17236 KB |
Output is correct |
8 |
Correct |
40 ms |
17220 KB |
Output is correct |
9 |
Correct |
43 ms |
17228 KB |
Output is correct |
10 |
Correct |
42 ms |
17236 KB |
Output is correct |
11 |
Correct |
34 ms |
17248 KB |
Output is correct |
12 |
Correct |
39 ms |
17152 KB |
Output is correct |
13 |
Correct |
39 ms |
17236 KB |
Output is correct |
14 |
Correct |
10 ms |
17236 KB |
Output is correct |
15 |
Correct |
12 ms |
17168 KB |
Output is correct |
16 |
Correct |
39 ms |
17240 KB |
Output is correct |
17 |
Correct |
40 ms |
17252 KB |
Output is correct |
18 |
Correct |
40 ms |
17224 KB |
Output is correct |
19 |
Correct |
40 ms |
17216 KB |
Output is correct |
20 |
Correct |
40 ms |
17236 KB |
Output is correct |
21 |
Correct |
39 ms |
17236 KB |
Output is correct |
22 |
Correct |
39 ms |
17236 KB |
Output is correct |
23 |
Correct |
39 ms |
17128 KB |
Output is correct |
24 |
Correct |
39 ms |
17216 KB |
Output is correct |
25 |
Correct |
40 ms |
17228 KB |
Output is correct |
26 |
Correct |
39 ms |
17236 KB |
Output is correct |
27 |
Correct |
40 ms |
17236 KB |
Output is correct |
28 |
Correct |
38 ms |
17228 KB |
Output is correct |
29 |
Correct |
86 ms |
17240 KB |
Output is correct |
30 |
Correct |
72 ms |
17236 KB |
Output is correct |
31 |
Correct |
64 ms |
17252 KB |
Output is correct |
32 |
Correct |
55 ms |
17236 KB |
Output is correct |
33 |
Correct |
42 ms |
17236 KB |
Output is correct |
34 |
Correct |
118 ms |
17236 KB |
Output is correct |
35 |
Correct |
111 ms |
17284 KB |
Output is correct |
36 |
Correct |
112 ms |
17236 KB |
Output is correct |
37 |
Correct |
76 ms |
17236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17224 KB |
Output is correct |
2 |
Correct |
8 ms |
17236 KB |
Output is correct |
3 |
Correct |
39 ms |
17236 KB |
Output is correct |
4 |
Correct |
39 ms |
17236 KB |
Output is correct |
5 |
Correct |
39 ms |
17244 KB |
Output is correct |
6 |
Correct |
39 ms |
17176 KB |
Output is correct |
7 |
Correct |
42 ms |
17236 KB |
Output is correct |
8 |
Correct |
40 ms |
17220 KB |
Output is correct |
9 |
Correct |
43 ms |
17228 KB |
Output is correct |
10 |
Correct |
42 ms |
17236 KB |
Output is correct |
11 |
Correct |
34 ms |
17248 KB |
Output is correct |
12 |
Correct |
39 ms |
17152 KB |
Output is correct |
13 |
Correct |
39 ms |
17236 KB |
Output is correct |
14 |
Correct |
10 ms |
17236 KB |
Output is correct |
15 |
Correct |
12 ms |
17168 KB |
Output is correct |
16 |
Correct |
39 ms |
17240 KB |
Output is correct |
17 |
Correct |
40 ms |
17252 KB |
Output is correct |
18 |
Correct |
40 ms |
17224 KB |
Output is correct |
19 |
Correct |
40 ms |
17216 KB |
Output is correct |
20 |
Correct |
40 ms |
17236 KB |
Output is correct |
21 |
Correct |
39 ms |
17236 KB |
Output is correct |
22 |
Correct |
39 ms |
17236 KB |
Output is correct |
23 |
Correct |
39 ms |
17128 KB |
Output is correct |
24 |
Correct |
39 ms |
17216 KB |
Output is correct |
25 |
Correct |
40 ms |
17228 KB |
Output is correct |
26 |
Correct |
39 ms |
17236 KB |
Output is correct |
27 |
Correct |
40 ms |
17236 KB |
Output is correct |
28 |
Correct |
38 ms |
17228 KB |
Output is correct |
29 |
Correct |
86 ms |
17240 KB |
Output is correct |
30 |
Correct |
72 ms |
17236 KB |
Output is correct |
31 |
Correct |
64 ms |
17252 KB |
Output is correct |
32 |
Correct |
55 ms |
17236 KB |
Output is correct |
33 |
Correct |
42 ms |
17236 KB |
Output is correct |
34 |
Correct |
118 ms |
17236 KB |
Output is correct |
35 |
Correct |
111 ms |
17284 KB |
Output is correct |
36 |
Correct |
112 ms |
17236 KB |
Output is correct |
37 |
Correct |
76 ms |
17236 KB |
Output is correct |
38 |
Correct |
1228 ms |
19960 KB |
Output is correct |
39 |
Correct |
120 ms |
30364 KB |
Output is correct |
40 |
Correct |
1795 ms |
19876 KB |
Output is correct |
41 |
Correct |
1841 ms |
18788 KB |
Output is correct |
42 |
Correct |
1837 ms |
20216 KB |
Output is correct |
43 |
Correct |
76 ms |
18712 KB |
Output is correct |
44 |
Correct |
1800 ms |
17852 KB |
Output is correct |
45 |
Correct |
162 ms |
23372 KB |
Output is correct |
46 |
Correct |
162 ms |
23360 KB |
Output is correct |
47 |
Correct |
163 ms |
26180 KB |
Output is correct |
48 |
Correct |
161 ms |
26060 KB |
Output is correct |
49 |
Correct |
161 ms |
23500 KB |
Output is correct |
50 |
Correct |
155 ms |
23372 KB |
Output is correct |
51 |
Correct |
81 ms |
24268 KB |
Output is correct |
52 |
Correct |
80 ms |
24296 KB |
Output is correct |
53 |
Correct |
1691 ms |
17916 KB |
Output is correct |
54 |
Correct |
172 ms |
23300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
17236 KB |
Output is correct |
2 |
Correct |
10 ms |
17236 KB |
Output is correct |
3 |
Correct |
12 ms |
17236 KB |
Output is correct |
4 |
Correct |
8 ms |
17184 KB |
Output is correct |
5 |
Correct |
1602 ms |
17220 KB |
Output is correct |
6 |
Correct |
39 ms |
17236 KB |
Output is correct |
7 |
Correct |
38 ms |
17240 KB |
Output is correct |
8 |
Correct |
38 ms |
17216 KB |
Output is correct |
9 |
Correct |
39 ms |
17236 KB |
Output is correct |
10 |
Correct |
40 ms |
17216 KB |
Output is correct |
11 |
Correct |
42 ms |
17236 KB |
Output is correct |
12 |
Correct |
108 ms |
17240 KB |
Output is correct |
13 |
Correct |
2268 ms |
17496 KB |
Output is correct |
14 |
Correct |
1887 ms |
17236 KB |
Output is correct |
15 |
Correct |
2124 ms |
17244 KB |
Output is correct |
16 |
Execution timed out |
5051 ms |
22452 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
17236 KB |
Output is correct |
2 |
Correct |
12 ms |
17256 KB |
Output is correct |
3 |
Correct |
9 ms |
17236 KB |
Output is correct |
4 |
Correct |
779 ms |
17236 KB |
Output is correct |
5 |
Correct |
1608 ms |
17232 KB |
Output is correct |
6 |
Correct |
40 ms |
17236 KB |
Output is correct |
7 |
Correct |
40 ms |
17244 KB |
Output is correct |
8 |
Correct |
87 ms |
17304 KB |
Output is correct |
9 |
Correct |
1222 ms |
19776 KB |
Output is correct |
10 |
Correct |
132 ms |
30268 KB |
Output is correct |
11 |
Correct |
1595 ms |
17484 KB |
Output is correct |
12 |
Correct |
2073 ms |
18252 KB |
Output is correct |
13 |
Execution timed out |
5058 ms |
30100 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |