Submission #874669

# Submission time Handle Problem Language Result Execution time Memory
874669 2023-11-17T14:20:49 Z winter0101 Jail (JOI22_jail) C++14
100 / 100
803 ms 115560 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define lastbit(i) __builtin_ctz(i)
const int maxn=1e5+2e4+9;
vector<int>a[maxn];
pii b[maxn];
int sub[maxn];
int d[maxn],p[maxn];
void dfs(int u,int par){
sub[u]=1;
for (auto &v:a[u]){
if (v==par)continue;
d[v]=d[u]+1;
p[v]=u;
dfs(v,u);
sub[u]+=sub[v];
if (a[u][0]==par||sub[a[u][0]]<sub[v])swap(a[u][0],v);
}
}
int pos[maxn],h[maxn],tle=0,rev[maxn];
void hld(int u,int par,int head){
pos[u]=++tle;
h[u]=head;
if (a[u][0]!=par){
hld(a[u][0],u,head);
}
for (auto v:a[u]){
    if (v==par||v==a[u][0])continue;
    hld(v,u,v);
}
}
vector<int>g[maxn*9];//two segtree and m
bool fl=1;
int low[maxn*9],num[maxn*9],tme=0;
int n,m;
void build(int id,int l,int r){
if (l==r){
rev[l]=id;
return;
}
int mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
//->
g[id].pb(id*2);
g[id].pb(id*2+1);
g[id*2+4*n].pb(id+4*n);
g[id*2+1+4*n].pb(id+4*n);
}
void addedg(int id,int l,int r,int u,int v,int ver){
if (l>v||r<u||u>v)return;
//cout<<l<<" "<<r<<" "<<u<<" "<<v<<'\n';
if (u<=l&&r<=v){
g[ver+8*n].pb(id);
g[id+4*n].pb(ver+8*n);
return;
}
int mid=(l+r)/2;
addedg(id*2,l,mid,u,v,ver);
addedg(id*2+1,mid+1,r,u,v,ver);
}
void takepath(int id,int u,int v){
bool f1=1,f2=1;
while (h[u]!=h[v]){
if (d[h[u]]<d[h[v]]){
swap(f1,f2);
swap(u,v);
}
addedg(1,1,n,pos[h[u]],pos[u]-f1,id);
f1=0;
u=p[h[u]];
}
if (pos[u]>pos[v]){
swap(u,v);
swap(f1,f2);
}
addedg(1,1,n,pos[u]+f1,pos[v]-f2,id);
}
stack<int>t;
void redfs(int u){
t.push(u);
low[u]=num[u]=++tme;
for (auto v:g[u]){
if (num[v]==-1)continue;
if (num[v])low[u]=min(low[u],low[v]);
else {
    redfs(v);
    low[u]=min(low[u],low[v]);
}
}
if (low[u]==num[u]){
    int dem=0;
    while (!t.empty()&&t.top()!=u){
    num[t.top()]=-1;
    dem+=(t.top()>8*n);
    t.pop();
    }
    dem+=(u>8*n);
    if (dem>1)fl=0;
    num[u]=-1;
    t.pop();
}
}
int t1[maxn];
void solve(){
    cin>>n;
    for1(i,1,n){
    a[i].clear();
    t1[i]=0;
    }
    for1(i,1,9*n){
    g[i].clear();
    num[i]=low[i]=0;
    }
    for1(i,1,n-1){
    int u,v;
    cin>>u>>v;
    a[u].pb(v);
    a[v].pb(u);
    }
    dfs(1,0);
    tle=0;
    hld(1,0,1);
    build(1,1,n);
    cin>>m;
    for1(i,1,m){
    cin>>b[i].fi>>b[i].se;
    g[i+8*n].pb(rev[pos[b[i].fi]]+4*n);
    g[rev[pos[b[i].se]]].pb(i+8*n);
    t1[b[i].se]=i;
    takepath(i,b[i].fi,b[i].se);
    }
    for1(i,1,m){
    if (t1[b[i].fi]){
    g[i+8*n].pb(t1[b[i].fi]+8*n);
    //cout<<i<<" "<<t1[b[i].fi]<<'\n';
    }
    }
    //takepath(2,b[2].fi,b[2].se);
    tme=0;
    fl=1;
    for1(i,1,8*n+m)if (!num[i])redfs(i);
    if (fl)cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int test=1;
    cin>>test;
    while (test--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 8 ms 36996 KB Output is correct
4 Correct 19 ms 37452 KB Output is correct
5 Correct 30 ms 37724 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 10 ms 37128 KB Output is correct
8 Correct 9 ms 36952 KB Output is correct
9 Correct 44 ms 39508 KB Output is correct
10 Correct 96 ms 67260 KB Output is correct
11 Correct 14 ms 36956 KB Output is correct
12 Correct 42 ms 37972 KB Output is correct
13 Correct 132 ms 72576 KB Output is correct
14 Correct 139 ms 74332 KB Output is correct
15 Correct 265 ms 84308 KB Output is correct
16 Correct 560 ms 115560 KB Output is correct
17 Correct 159 ms 80980 KB Output is correct
18 Correct 135 ms 75988 KB Output is correct
19 Correct 151 ms 78548 KB Output is correct
20 Correct 151 ms 78416 KB Output is correct
21 Correct 213 ms 81236 KB Output is correct
22 Correct 99 ms 73300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 9 ms 37132 KB Output is correct
4 Correct 10 ms 36956 KB Output is correct
5 Correct 10 ms 36956 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 9 ms 36956 KB Output is correct
8 Correct 9 ms 36956 KB Output is correct
9 Correct 9 ms 36956 KB Output is correct
10 Correct 9 ms 36956 KB Output is correct
11 Correct 9 ms 37112 KB Output is correct
12 Correct 8 ms 36956 KB Output is correct
13 Correct 8 ms 37056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 9 ms 37132 KB Output is correct
4 Correct 10 ms 36956 KB Output is correct
5 Correct 10 ms 36956 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 9 ms 36956 KB Output is correct
8 Correct 9 ms 36956 KB Output is correct
9 Correct 9 ms 36956 KB Output is correct
10 Correct 9 ms 36956 KB Output is correct
11 Correct 9 ms 37112 KB Output is correct
12 Correct 8 ms 36956 KB Output is correct
13 Correct 8 ms 37056 KB Output is correct
14 Correct 8 ms 37036 KB Output is correct
15 Correct 9 ms 36960 KB Output is correct
16 Correct 9 ms 37120 KB Output is correct
17 Correct 9 ms 36956 KB Output is correct
18 Correct 9 ms 36988 KB Output is correct
19 Correct 8 ms 36956 KB Output is correct
20 Correct 9 ms 37120 KB Output is correct
21 Correct 9 ms 36952 KB Output is correct
22 Correct 9 ms 36952 KB Output is correct
23 Correct 8 ms 36956 KB Output is correct
24 Correct 8 ms 36956 KB Output is correct
25 Correct 9 ms 37112 KB Output is correct
26 Correct 8 ms 36956 KB Output is correct
27 Correct 9 ms 36956 KB Output is correct
28 Correct 8 ms 36956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 9 ms 37132 KB Output is correct
4 Correct 10 ms 36956 KB Output is correct
5 Correct 10 ms 36956 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 9 ms 36956 KB Output is correct
8 Correct 9 ms 36956 KB Output is correct
9 Correct 9 ms 36956 KB Output is correct
10 Correct 9 ms 36956 KB Output is correct
11 Correct 9 ms 37112 KB Output is correct
12 Correct 8 ms 36956 KB Output is correct
13 Correct 8 ms 37056 KB Output is correct
14 Correct 8 ms 37036 KB Output is correct
15 Correct 9 ms 36960 KB Output is correct
16 Correct 9 ms 37120 KB Output is correct
17 Correct 9 ms 36956 KB Output is correct
18 Correct 9 ms 36988 KB Output is correct
19 Correct 8 ms 36956 KB Output is correct
20 Correct 9 ms 37120 KB Output is correct
21 Correct 9 ms 36952 KB Output is correct
22 Correct 9 ms 36952 KB Output is correct
23 Correct 8 ms 36956 KB Output is correct
24 Correct 8 ms 36956 KB Output is correct
25 Correct 9 ms 37112 KB Output is correct
26 Correct 8 ms 36956 KB Output is correct
27 Correct 9 ms 36956 KB Output is correct
28 Correct 8 ms 36956 KB Output is correct
29 Correct 10 ms 36956 KB Output is correct
30 Correct 10 ms 36976 KB Output is correct
31 Correct 10 ms 36956 KB Output is correct
32 Correct 10 ms 37132 KB Output is correct
33 Correct 9 ms 37208 KB Output is correct
34 Correct 10 ms 37136 KB Output is correct
35 Correct 12 ms 37148 KB Output is correct
36 Correct 10 ms 36956 KB Output is correct
37 Correct 10 ms 36996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 9 ms 37132 KB Output is correct
4 Correct 10 ms 36956 KB Output is correct
5 Correct 10 ms 36956 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 9 ms 36956 KB Output is correct
8 Correct 9 ms 36956 KB Output is correct
9 Correct 9 ms 36956 KB Output is correct
10 Correct 9 ms 36956 KB Output is correct
11 Correct 9 ms 37112 KB Output is correct
12 Correct 8 ms 36956 KB Output is correct
13 Correct 8 ms 37056 KB Output is correct
14 Correct 8 ms 37036 KB Output is correct
15 Correct 9 ms 36960 KB Output is correct
16 Correct 9 ms 37120 KB Output is correct
17 Correct 9 ms 36956 KB Output is correct
18 Correct 9 ms 36988 KB Output is correct
19 Correct 8 ms 36956 KB Output is correct
20 Correct 9 ms 37120 KB Output is correct
21 Correct 9 ms 36952 KB Output is correct
22 Correct 9 ms 36952 KB Output is correct
23 Correct 8 ms 36956 KB Output is correct
24 Correct 8 ms 36956 KB Output is correct
25 Correct 9 ms 37112 KB Output is correct
26 Correct 8 ms 36956 KB Output is correct
27 Correct 9 ms 36956 KB Output is correct
28 Correct 8 ms 36956 KB Output is correct
29 Correct 10 ms 36956 KB Output is correct
30 Correct 10 ms 36976 KB Output is correct
31 Correct 10 ms 36956 KB Output is correct
32 Correct 10 ms 37132 KB Output is correct
33 Correct 9 ms 37208 KB Output is correct
34 Correct 10 ms 37136 KB Output is correct
35 Correct 12 ms 37148 KB Output is correct
36 Correct 10 ms 36956 KB Output is correct
37 Correct 10 ms 36996 KB Output is correct
38 Correct 41 ms 39540 KB Output is correct
39 Correct 81 ms 67276 KB Output is correct
40 Correct 50 ms 39508 KB Output is correct
41 Correct 53 ms 39256 KB Output is correct
42 Correct 41 ms 39504 KB Output is correct
43 Correct 37 ms 39024 KB Output is correct
44 Correct 20 ms 37464 KB Output is correct
45 Correct 89 ms 57680 KB Output is correct
46 Correct 87 ms 57696 KB Output is correct
47 Correct 86 ms 62528 KB Output is correct
48 Correct 80 ms 62496 KB Output is correct
49 Correct 84 ms 57940 KB Output is correct
50 Correct 83 ms 57880 KB Output is correct
51 Correct 85 ms 59468 KB Output is correct
52 Correct 83 ms 59988 KB Output is correct
53 Correct 20 ms 38748 KB Output is correct
54 Correct 98 ms 57768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 37040 KB Output is correct
2 Correct 8 ms 36952 KB Output is correct
3 Correct 8 ms 36952 KB Output is correct
4 Correct 8 ms 36968 KB Output is correct
5 Correct 14 ms 37200 KB Output is correct
6 Correct 11 ms 36956 KB Output is correct
7 Correct 9 ms 36956 KB Output is correct
8 Correct 9 ms 36976 KB Output is correct
9 Correct 8 ms 36956 KB Output is correct
10 Correct 9 ms 36952 KB Output is correct
11 Correct 8 ms 36956 KB Output is correct
12 Correct 9 ms 36956 KB Output is correct
13 Correct 32 ms 37448 KB Output is correct
14 Correct 50 ms 37720 KB Output is correct
15 Correct 38 ms 37720 KB Output is correct
16 Correct 121 ms 59328 KB Output is correct
17 Correct 318 ms 72040 KB Output is correct
18 Correct 568 ms 92136 KB Output is correct
19 Correct 216 ms 61188 KB Output is correct
20 Correct 175 ms 61268 KB Output is correct
21 Correct 180 ms 61268 KB Output is correct
22 Correct 304 ms 69436 KB Output is correct
23 Correct 217 ms 68484 KB Output is correct
24 Correct 254 ms 68048 KB Output is correct
25 Correct 225 ms 68304 KB Output is correct
26 Correct 227 ms 68172 KB Output is correct
27 Correct 201 ms 71880 KB Output is correct
28 Correct 220 ms 77372 KB Output is correct
29 Correct 211 ms 72284 KB Output is correct
30 Correct 205 ms 66768 KB Output is correct
31 Correct 238 ms 72656 KB Output is correct
32 Correct 200 ms 68364 KB Output is correct
33 Correct 220 ms 72548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 36956 KB Output is correct
2 Correct 8 ms 36956 KB Output is correct
3 Correct 8 ms 36996 KB Output is correct
4 Correct 19 ms 37452 KB Output is correct
5 Correct 30 ms 37724 KB Output is correct
6 Correct 9 ms 36956 KB Output is correct
7 Correct 10 ms 37128 KB Output is correct
8 Correct 9 ms 36952 KB Output is correct
9 Correct 44 ms 39508 KB Output is correct
10 Correct 96 ms 67260 KB Output is correct
11 Correct 14 ms 36956 KB Output is correct
12 Correct 42 ms 37972 KB Output is correct
13 Correct 132 ms 72576 KB Output is correct
14 Correct 139 ms 74332 KB Output is correct
15 Correct 265 ms 84308 KB Output is correct
16 Correct 560 ms 115560 KB Output is correct
17 Correct 159 ms 80980 KB Output is correct
18 Correct 135 ms 75988 KB Output is correct
19 Correct 151 ms 78548 KB Output is correct
20 Correct 151 ms 78416 KB Output is correct
21 Correct 213 ms 81236 KB Output is correct
22 Correct 99 ms 73300 KB Output is correct
23 Correct 8 ms 36956 KB Output is correct
24 Correct 8 ms 36956 KB Output is correct
25 Correct 9 ms 37132 KB Output is correct
26 Correct 10 ms 36956 KB Output is correct
27 Correct 10 ms 36956 KB Output is correct
28 Correct 9 ms 36956 KB Output is correct
29 Correct 9 ms 36956 KB Output is correct
30 Correct 9 ms 36956 KB Output is correct
31 Correct 9 ms 36956 KB Output is correct
32 Correct 9 ms 36956 KB Output is correct
33 Correct 9 ms 37112 KB Output is correct
34 Correct 8 ms 36956 KB Output is correct
35 Correct 8 ms 37056 KB Output is correct
36 Correct 8 ms 37036 KB Output is correct
37 Correct 9 ms 36960 KB Output is correct
38 Correct 9 ms 37120 KB Output is correct
39 Correct 9 ms 36956 KB Output is correct
40 Correct 9 ms 36988 KB Output is correct
41 Correct 8 ms 36956 KB Output is correct
42 Correct 9 ms 37120 KB Output is correct
43 Correct 9 ms 36952 KB Output is correct
44 Correct 9 ms 36952 KB Output is correct
45 Correct 8 ms 36956 KB Output is correct
46 Correct 8 ms 36956 KB Output is correct
47 Correct 9 ms 37112 KB Output is correct
48 Correct 8 ms 36956 KB Output is correct
49 Correct 9 ms 36956 KB Output is correct
50 Correct 8 ms 36956 KB Output is correct
51 Correct 10 ms 36956 KB Output is correct
52 Correct 10 ms 36976 KB Output is correct
53 Correct 10 ms 36956 KB Output is correct
54 Correct 10 ms 37132 KB Output is correct
55 Correct 9 ms 37208 KB Output is correct
56 Correct 10 ms 37136 KB Output is correct
57 Correct 12 ms 37148 KB Output is correct
58 Correct 10 ms 36956 KB Output is correct
59 Correct 10 ms 36996 KB Output is correct
60 Correct 41 ms 39540 KB Output is correct
61 Correct 81 ms 67276 KB Output is correct
62 Correct 50 ms 39508 KB Output is correct
63 Correct 53 ms 39256 KB Output is correct
64 Correct 41 ms 39504 KB Output is correct
65 Correct 37 ms 39024 KB Output is correct
66 Correct 20 ms 37464 KB Output is correct
67 Correct 89 ms 57680 KB Output is correct
68 Correct 87 ms 57696 KB Output is correct
69 Correct 86 ms 62528 KB Output is correct
70 Correct 80 ms 62496 KB Output is correct
71 Correct 84 ms 57940 KB Output is correct
72 Correct 83 ms 57880 KB Output is correct
73 Correct 85 ms 59468 KB Output is correct
74 Correct 83 ms 59988 KB Output is correct
75 Correct 20 ms 38748 KB Output is correct
76 Correct 98 ms 57768 KB Output is correct
77 Correct 9 ms 37040 KB Output is correct
78 Correct 8 ms 36952 KB Output is correct
79 Correct 8 ms 36952 KB Output is correct
80 Correct 8 ms 36968 KB Output is correct
81 Correct 14 ms 37200 KB Output is correct
82 Correct 11 ms 36956 KB Output is correct
83 Correct 9 ms 36956 KB Output is correct
84 Correct 9 ms 36976 KB Output is correct
85 Correct 8 ms 36956 KB Output is correct
86 Correct 9 ms 36952 KB Output is correct
87 Correct 8 ms 36956 KB Output is correct
88 Correct 9 ms 36956 KB Output is correct
89 Correct 32 ms 37448 KB Output is correct
90 Correct 50 ms 37720 KB Output is correct
91 Correct 38 ms 37720 KB Output is correct
92 Correct 121 ms 59328 KB Output is correct
93 Correct 318 ms 72040 KB Output is correct
94 Correct 568 ms 92136 KB Output is correct
95 Correct 216 ms 61188 KB Output is correct
96 Correct 175 ms 61268 KB Output is correct
97 Correct 180 ms 61268 KB Output is correct
98 Correct 304 ms 69436 KB Output is correct
99 Correct 217 ms 68484 KB Output is correct
100 Correct 254 ms 68048 KB Output is correct
101 Correct 225 ms 68304 KB Output is correct
102 Correct 227 ms 68172 KB Output is correct
103 Correct 201 ms 71880 KB Output is correct
104 Correct 220 ms 77372 KB Output is correct
105 Correct 211 ms 72284 KB Output is correct
106 Correct 205 ms 66768 KB Output is correct
107 Correct 238 ms 72656 KB Output is correct
108 Correct 200 ms 68364 KB Output is correct
109 Correct 220 ms 72548 KB Output is correct
110 Correct 53 ms 38228 KB Output is correct
111 Correct 30 ms 37716 KB Output is correct
112 Correct 363 ms 83492 KB Output is correct
113 Correct 142 ms 66608 KB Output is correct
114 Correct 240 ms 74052 KB Output is correct
115 Correct 81 ms 58060 KB Output is correct
116 Correct 146 ms 62560 KB Output is correct
117 Correct 803 ms 106048 KB Output is correct
118 Correct 122 ms 57964 KB Output is correct
119 Correct 93 ms 57948 KB Output is correct
120 Correct 18 ms 38748 KB Output is correct
121 Correct 210 ms 63772 KB Output is correct
122 Correct 197 ms 63668 KB Output is correct
123 Correct 151 ms 69460 KB Output is correct
124 Correct 154 ms 69164 KB Output is correct
125 Correct 164 ms 69880 KB Output is correct
126 Correct 562 ms 109632 KB Output is correct
127 Correct 266 ms 81888 KB Output is correct
128 Correct 208 ms 80808 KB Output is correct
129 Correct 194 ms 78748 KB Output is correct
130 Correct 200 ms 80172 KB Output is correct