# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
567046 |
2022-05-23T07:35:52 Z |
zaneyu |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
522584 KB |
/*input
1
5
1 2
1 3
1 4
4 5
2
1 2
2 5
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return a*b%MOD;
}
ll mypow(ll a,ll b){
a%=MOD;
if(a==0) return 0;
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=(res*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
bool wk=1;
vector<int> v[maxn];
int in[maxn],out[maxn];
vector<int> vv[maxn];
int vis[maxn];
int par[maxn];
int dep[maxn];
void dfs(int u,int p){
par[u]=p;
for(int x:v[u]){
if(x==p) continue;
dep[x]=dep[u]+1;
dfs(x,u);
}
}
void dfs2(int u){
vis[u]=1;
for(int x:vv[u]){
if(!vis[x]) dfs2(x);
else if(vis[x]==1){
wk=0;
break;
}
}
vis[u]=2;
}
void solve(){
int n,m;
cin>>n;
REP(i,n-1){
int a,b;
cin>>a>>b;
--a,--b;
v[a].pb(b),v[b].pb(a);
}
dfs(0,-1);
cin>>m;
vector<pii> asd;
REP1(i,m){
int a,b;
cin>>a>>b;
--a,--b;
in[a]=i,out[b]=i;
asd.pb({a,b});
}
REP(i,sz(asd)){
int a=asd[i].f,b=asd[i].s;
int cur=i+1;
if(in[b]) vv[in[b]].pb(cur);
if(out[a]) vv[cur].pb(out[a]);
vector<int> pth;
while(a!=b){
if(dep[a]>dep[b]){
a=par[a];
pth.pb(a);
}
else{
b=par[b];
pth.pb(b);
}
}
SORT_UNIQUE(pth);
for(int x:pth){
if(x==asd[i].f or x==asd[i].s) continue;
if(in[x]) vv[in[x]].pb(cur);
if(out[x]) vv[cur].pb(out[x]);
}
}
wk=1;
REP1(i,m){
if(!vis[i]) dfs2(i);
}
if(wk){
cout<<"Yes\n";
}
else cout<<"No\n";
REP(i,n) v[i].clear(),in[i]=out[i]=0;
REP1(i,m) vv[i].clear(),vis[i]=0;
}
int main(){
int t;
cin>>t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9752 KB |
Output is correct |
4 |
Correct |
33 ms |
9656 KB |
Output is correct |
5 |
Correct |
61 ms |
9696 KB |
Output is correct |
6 |
Correct |
11 ms |
9684 KB |
Output is correct |
7 |
Correct |
9 ms |
9624 KB |
Output is correct |
8 |
Correct |
12 ms |
9812 KB |
Output is correct |
9 |
Correct |
343 ms |
12240 KB |
Output is correct |
10 |
Correct |
1645 ms |
20508 KB |
Output is correct |
11 |
Correct |
19 ms |
9684 KB |
Output is correct |
12 |
Correct |
92 ms |
9824 KB |
Output is correct |
13 |
Correct |
331 ms |
49304 KB |
Output is correct |
14 |
Correct |
340 ms |
63808 KB |
Output is correct |
15 |
Execution timed out |
5071 ms |
522584 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9624 KB |
Output is correct |
5 |
Correct |
8 ms |
9776 KB |
Output is correct |
6 |
Correct |
8 ms |
9724 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
7 ms |
9720 KB |
Output is correct |
9 |
Correct |
8 ms |
9704 KB |
Output is correct |
10 |
Correct |
8 ms |
9768 KB |
Output is correct |
11 |
Correct |
7 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9684 KB |
Output is correct |
13 |
Correct |
7 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9624 KB |
Output is correct |
5 |
Correct |
8 ms |
9776 KB |
Output is correct |
6 |
Correct |
8 ms |
9724 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
7 ms |
9720 KB |
Output is correct |
9 |
Correct |
8 ms |
9704 KB |
Output is correct |
10 |
Correct |
8 ms |
9768 KB |
Output is correct |
11 |
Correct |
7 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9684 KB |
Output is correct |
13 |
Correct |
7 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9712 KB |
Output is correct |
16 |
Correct |
9 ms |
9684 KB |
Output is correct |
17 |
Correct |
9 ms |
9684 KB |
Output is correct |
18 |
Correct |
8 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
7 ms |
9724 KB |
Output is correct |
21 |
Correct |
8 ms |
9728 KB |
Output is correct |
22 |
Correct |
8 ms |
9684 KB |
Output is correct |
23 |
Correct |
6 ms |
9704 KB |
Output is correct |
24 |
Correct |
6 ms |
9684 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
7 ms |
9684 KB |
Output is correct |
27 |
Correct |
10 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9624 KB |
Output is correct |
5 |
Correct |
8 ms |
9776 KB |
Output is correct |
6 |
Correct |
8 ms |
9724 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
7 ms |
9720 KB |
Output is correct |
9 |
Correct |
8 ms |
9704 KB |
Output is correct |
10 |
Correct |
8 ms |
9768 KB |
Output is correct |
11 |
Correct |
7 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9684 KB |
Output is correct |
13 |
Correct |
7 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9712 KB |
Output is correct |
16 |
Correct |
9 ms |
9684 KB |
Output is correct |
17 |
Correct |
9 ms |
9684 KB |
Output is correct |
18 |
Correct |
8 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
7 ms |
9724 KB |
Output is correct |
21 |
Correct |
8 ms |
9728 KB |
Output is correct |
22 |
Correct |
8 ms |
9684 KB |
Output is correct |
23 |
Correct |
6 ms |
9704 KB |
Output is correct |
24 |
Correct |
6 ms |
9684 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
7 ms |
9684 KB |
Output is correct |
27 |
Correct |
10 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
11 ms |
9856 KB |
Output is correct |
30 |
Correct |
8 ms |
9724 KB |
Output is correct |
31 |
Correct |
9 ms |
9812 KB |
Output is correct |
32 |
Correct |
11 ms |
9672 KB |
Output is correct |
33 |
Correct |
10 ms |
9684 KB |
Output is correct |
34 |
Correct |
9 ms |
9684 KB |
Output is correct |
35 |
Correct |
11 ms |
9812 KB |
Output is correct |
36 |
Correct |
8 ms |
9684 KB |
Output is correct |
37 |
Correct |
9 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9624 KB |
Output is correct |
5 |
Correct |
8 ms |
9776 KB |
Output is correct |
6 |
Correct |
8 ms |
9724 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
7 ms |
9720 KB |
Output is correct |
9 |
Correct |
8 ms |
9704 KB |
Output is correct |
10 |
Correct |
8 ms |
9768 KB |
Output is correct |
11 |
Correct |
7 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9684 KB |
Output is correct |
13 |
Correct |
7 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9712 KB |
Output is correct |
16 |
Correct |
9 ms |
9684 KB |
Output is correct |
17 |
Correct |
9 ms |
9684 KB |
Output is correct |
18 |
Correct |
8 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
7 ms |
9724 KB |
Output is correct |
21 |
Correct |
8 ms |
9728 KB |
Output is correct |
22 |
Correct |
8 ms |
9684 KB |
Output is correct |
23 |
Correct |
6 ms |
9704 KB |
Output is correct |
24 |
Correct |
6 ms |
9684 KB |
Output is correct |
25 |
Correct |
10 ms |
9720 KB |
Output is correct |
26 |
Correct |
7 ms |
9684 KB |
Output is correct |
27 |
Correct |
10 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
11 ms |
9856 KB |
Output is correct |
30 |
Correct |
8 ms |
9724 KB |
Output is correct |
31 |
Correct |
9 ms |
9812 KB |
Output is correct |
32 |
Correct |
11 ms |
9672 KB |
Output is correct |
33 |
Correct |
10 ms |
9684 KB |
Output is correct |
34 |
Correct |
9 ms |
9684 KB |
Output is correct |
35 |
Correct |
11 ms |
9812 KB |
Output is correct |
36 |
Correct |
8 ms |
9684 KB |
Output is correct |
37 |
Correct |
9 ms |
9684 KB |
Output is correct |
38 |
Correct |
277 ms |
12364 KB |
Output is correct |
39 |
Correct |
1432 ms |
20780 KB |
Output is correct |
40 |
Correct |
154 ms |
11372 KB |
Output is correct |
41 |
Correct |
70 ms |
10200 KB |
Output is correct |
42 |
Correct |
129 ms |
11588 KB |
Output is correct |
43 |
Correct |
69 ms |
10216 KB |
Output is correct |
44 |
Correct |
27 ms |
9976 KB |
Output is correct |
45 |
Correct |
102 ms |
15440 KB |
Output is correct |
46 |
Correct |
91 ms |
15436 KB |
Output is correct |
47 |
Correct |
329 ms |
17880 KB |
Output is correct |
48 |
Correct |
278 ms |
17788 KB |
Output is correct |
49 |
Correct |
103 ms |
15564 KB |
Output is correct |
50 |
Correct |
114 ms |
15604 KB |
Output is correct |
51 |
Correct |
86 ms |
16020 KB |
Output is correct |
52 |
Correct |
82 ms |
16032 KB |
Output is correct |
53 |
Correct |
25 ms |
10288 KB |
Output is correct |
54 |
Correct |
113 ms |
15352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
17 ms |
9732 KB |
Output is correct |
6 |
Correct |
6 ms |
9736 KB |
Output is correct |
7 |
Correct |
8 ms |
9724 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
8 ms |
9720 KB |
Output is correct |
13 |
Correct |
47 ms |
9860 KB |
Output is correct |
14 |
Correct |
71 ms |
9848 KB |
Output is correct |
15 |
Correct |
55 ms |
9868 KB |
Output is correct |
16 |
Correct |
104 ms |
15992 KB |
Output is correct |
17 |
Correct |
189 ms |
21836 KB |
Output is correct |
18 |
Correct |
416 ms |
41972 KB |
Output is correct |
19 |
Correct |
112 ms |
16132 KB |
Output is correct |
20 |
Correct |
121 ms |
15968 KB |
Output is correct |
21 |
Correct |
132 ms |
16076 KB |
Output is correct |
22 |
Correct |
204 ms |
22244 KB |
Output is correct |
23 |
Correct |
185 ms |
22728 KB |
Output is correct |
24 |
Correct |
169 ms |
22164 KB |
Output is correct |
25 |
Correct |
161 ms |
22132 KB |
Output is correct |
26 |
Correct |
173 ms |
22396 KB |
Output is correct |
27 |
Correct |
237 ms |
21916 KB |
Output is correct |
28 |
Correct |
243 ms |
24344 KB |
Output is correct |
29 |
Correct |
243 ms |
22620 KB |
Output is correct |
30 |
Correct |
160 ms |
19680 KB |
Output is correct |
31 |
Correct |
141 ms |
19936 KB |
Output is correct |
32 |
Correct |
149 ms |
19168 KB |
Output is correct |
33 |
Correct |
182 ms |
19980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9752 KB |
Output is correct |
4 |
Correct |
33 ms |
9656 KB |
Output is correct |
5 |
Correct |
61 ms |
9696 KB |
Output is correct |
6 |
Correct |
11 ms |
9684 KB |
Output is correct |
7 |
Correct |
9 ms |
9624 KB |
Output is correct |
8 |
Correct |
12 ms |
9812 KB |
Output is correct |
9 |
Correct |
343 ms |
12240 KB |
Output is correct |
10 |
Correct |
1645 ms |
20508 KB |
Output is correct |
11 |
Correct |
19 ms |
9684 KB |
Output is correct |
12 |
Correct |
92 ms |
9824 KB |
Output is correct |
13 |
Correct |
331 ms |
49304 KB |
Output is correct |
14 |
Correct |
340 ms |
63808 KB |
Output is correct |
15 |
Execution timed out |
5071 ms |
522584 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |