# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1006855 |
2024-06-24T09:19:55 Z |
modwwe |
Jail (JOI22_jail) |
C++17 |
|
969 ms |
85332 KB |
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b;
long long c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
// fin(task),fou(task);
#endif
NHP;
/// cin>>s1;
modwwe
phongbeo(),down
}
int st[17][120001];
int depth[120001];
int head[120001];
int pos[120001];
vector<int> v[120001];
ic a[1001];
int d[1001];
int heavy[120001];
bool b[1001];
int dfs(int x,int y)
{
int sz=1;
int mxz=0;
st[0][x]=y;
depth[x]=depth[y]+1;
for(auto f:v[x])
{
if(f!=y)
{
s2=dfs(f,x);
sz+=s2;
if(s2>mxz)
heavy[x]=f,mxz=s2;
}
}
return sz;
}
int lca(int x,int y)
{
if(depth[x]<depth[y]) swap(x,y);
int ss=depth[x]-depth[y];
if(ss!=0)
for(int j=0; j<17; ++j)
if(bit(ss,j))
x=st[j][x];
if(x==y) return x;
for(int j=16; j>=0; --j)
if(st[j][x]!=st[j][y])
x=st[j][x],y=st[j][y];
return st[0][x];
}
void des(int x,int y)
{
head[x]=y;
pos[x]=++dem;
if(heavy[x]!=0)
des(heavy[x],y);
for(auto f:v[x])
if(pos[f]==0)
des(f,f);
}
struct IT1
{
int t[480001];
void build(int node,int l,int r)
{
t[node]=0;
if(l==r) return;
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
}
void ff(int x)
{
for(int i=x*2; i<=x*2+1; i++)
t[i]+=t[x];
t[x]=0;
}
void upd(int node,int l,int r,int l1,int r1,int c)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1)
{
t[node]+=c;
return;
}
ff(node);
int mid=l+r>>1;
upd(node<<1,l,mid,l1,r1,c);
upd(node<<1|1,mid+1,r,l1,r1,c);
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node];
ff(node);
int mid=l+r>>1;
return get(node<<1,l,mid,l1,r1)+get(node<<1|1,mid+1,r,l1,r1);
}
} st1;
void upd_hld(int x,int y,int c)
{
if(pos[head[x]]<=pos[y])
{
st1.upd(1,1,n,pos[y],pos[x],c);
}
else
{
st1.upd(1,1,n,pos[head[x]],pos[x],c);
upd_hld(st[0][head[x]],y,c);
}
}
bool check2(int x)
{
s3=st1.get(1,1,n,pos[x],pos[x]);
if(s3==1) return 1;
return 0;
}
void upd(int x,int y)
{
for(int i=1; i<=m; i++)
{
if(i==x) continue;
s2=a[x].a;
s3=lca(s2,a[i].a);
s4=lca(s2,a[i].b);
if(s3==s2)
{
if(depth[s2]>=depth[a[i].c])
d[i]+=y;
}
else if(s4==s2)
{
if(depth[s2]>=depth[a[i].c])
d[i]+=y;
}
}
}
void phongbeo()
{
cin>>n;
st1.build(1,1,n);
dem=0;
for(int i=1; i<=n; i++)
pos[i]=0,heavy[i]=0,head[i]=0,v[i].clear(),depth[i]=0;
for(int i=1; i<=n; i++)
v[i].clear();
for(int i=1; i<n; i++)
{
cin>>l>>r;
v[l].pb(r);
v[r].pb(l);
}
dfs(1,0);
for(int i=1; i<17; i++)
for(int j=1; j<=n; j++)
st[i][j]=st[i-1][st[i-1][j]];
des(1,1);
cin>>m;
for(int i=1; i<=m; i++)
cin>>a[i].a>>a[i].b,a[i].c=lca(a[i].a,a[i].b),
upd_hld(a[i].a,a[i].c,1),
upd_hld(a[i].b,a[i].c,1),
upd_hld(a[i].c,a[i].c,-1),
d[i]=0,
b[i]=0;
for(int i=1; i<=m; i++)
upd(i,1);
for(int i=1; i<=m; i++)
{
bool de=0;
for(int j=1; j<=m; j++)
{
if(b[j]) continue;
if(d[j]==0&&check2(a[j].b))
{
upd_hld(a[j].a,a[j].c,-1),
upd_hld(a[j].b,a[j].c,-1),
upd_hld(a[j].c,a[j].c,1);
upd(j,-1);
b[j]=1;
de=1;
s10=j;
break;
}
}
if(!de)
{
cout<<"No";
return;
}
}
cout<<"Yes";
}
/*
NO 1
NO 1
*/
Compilation message
jail.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main()
| ^~~~
jail.cpp: In member function 'void IT1::build(int, int, int)':
jail.cpp:115:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
115 | int mid=l+r>>1;
| ~^~
jail.cpp: In member function 'void IT1::upd(int, int, int, int, int, int)':
jail.cpp:134:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
134 | int mid=l+r>>1;
| ~^~
jail.cpp: In member function 'int IT1::get(int, int, int, int, int)':
jail.cpp:143:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
143 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
8 ms |
14940 KB |
Output is correct |
5 |
Correct |
16 ms |
15452 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14852 KB |
Output is correct |
8 |
Correct |
17 ms |
14924 KB |
Output is correct |
9 |
Correct |
563 ms |
17316 KB |
Output is correct |
10 |
Correct |
51 ms |
42580 KB |
Output is correct |
11 |
Correct |
10 ms |
14940 KB |
Output is correct |
12 |
Correct |
181 ms |
15596 KB |
Output is correct |
13 |
Runtime error |
87 ms |
85332 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14824 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
3 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
3 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14824 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
3 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
3 ms |
14684 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
2 ms |
14916 KB |
Output is correct |
17 |
Correct |
4 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14844 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
3 ms |
14684 KB |
Output is correct |
21 |
Correct |
3 ms |
14848 KB |
Output is correct |
22 |
Correct |
3 ms |
14684 KB |
Output is correct |
23 |
Correct |
2 ms |
14684 KB |
Output is correct |
24 |
Correct |
2 ms |
14684 KB |
Output is correct |
25 |
Correct |
3 ms |
14840 KB |
Output is correct |
26 |
Correct |
2 ms |
14684 KB |
Output is correct |
27 |
Correct |
3 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14824 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
3 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
3 ms |
14684 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
2 ms |
14916 KB |
Output is correct |
17 |
Correct |
4 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14844 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
3 ms |
14684 KB |
Output is correct |
21 |
Correct |
3 ms |
14848 KB |
Output is correct |
22 |
Correct |
3 ms |
14684 KB |
Output is correct |
23 |
Correct |
2 ms |
14684 KB |
Output is correct |
24 |
Correct |
2 ms |
14684 KB |
Output is correct |
25 |
Correct |
3 ms |
14840 KB |
Output is correct |
26 |
Correct |
2 ms |
14684 KB |
Output is correct |
27 |
Correct |
3 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
14684 KB |
Output is correct |
29 |
Correct |
18 ms |
14684 KB |
Output is correct |
30 |
Correct |
11 ms |
14884 KB |
Output is correct |
31 |
Correct |
12 ms |
14940 KB |
Output is correct |
32 |
Correct |
11 ms |
14816 KB |
Output is correct |
33 |
Correct |
4 ms |
14684 KB |
Output is correct |
34 |
Correct |
20 ms |
14768 KB |
Output is correct |
35 |
Correct |
26 ms |
14684 KB |
Output is correct |
36 |
Correct |
20 ms |
14684 KB |
Output is correct |
37 |
Correct |
21 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14824 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
3 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
3 ms |
14684 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
2 ms |
14916 KB |
Output is correct |
17 |
Correct |
4 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14844 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
3 ms |
14684 KB |
Output is correct |
21 |
Correct |
3 ms |
14848 KB |
Output is correct |
22 |
Correct |
3 ms |
14684 KB |
Output is correct |
23 |
Correct |
2 ms |
14684 KB |
Output is correct |
24 |
Correct |
2 ms |
14684 KB |
Output is correct |
25 |
Correct |
3 ms |
14840 KB |
Output is correct |
26 |
Correct |
2 ms |
14684 KB |
Output is correct |
27 |
Correct |
3 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
14684 KB |
Output is correct |
29 |
Correct |
18 ms |
14684 KB |
Output is correct |
30 |
Correct |
11 ms |
14884 KB |
Output is correct |
31 |
Correct |
12 ms |
14940 KB |
Output is correct |
32 |
Correct |
11 ms |
14816 KB |
Output is correct |
33 |
Correct |
4 ms |
14684 KB |
Output is correct |
34 |
Correct |
20 ms |
14768 KB |
Output is correct |
35 |
Correct |
26 ms |
14684 KB |
Output is correct |
36 |
Correct |
20 ms |
14684 KB |
Output is correct |
37 |
Correct |
21 ms |
14684 KB |
Output is correct |
38 |
Correct |
619 ms |
17236 KB |
Output is correct |
39 |
Correct |
50 ms |
42580 KB |
Output is correct |
40 |
Correct |
755 ms |
16724 KB |
Output is correct |
41 |
Correct |
969 ms |
16212 KB |
Output is correct |
42 |
Correct |
569 ms |
16724 KB |
Output is correct |
43 |
Correct |
30 ms |
16476 KB |
Output is correct |
44 |
Correct |
429 ms |
14940 KB |
Output is correct |
45 |
Correct |
127 ms |
20052 KB |
Output is correct |
46 |
Correct |
128 ms |
20052 KB |
Output is correct |
47 |
Correct |
133 ms |
31224 KB |
Output is correct |
48 |
Correct |
137 ms |
31496 KB |
Output is correct |
49 |
Correct |
125 ms |
20728 KB |
Output is correct |
50 |
Correct |
151 ms |
20564 KB |
Output is correct |
51 |
Correct |
47 ms |
23992 KB |
Output is correct |
52 |
Correct |
57 ms |
23992 KB |
Output is correct |
53 |
Correct |
454 ms |
15312 KB |
Output is correct |
54 |
Correct |
103 ms |
20116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
9 ms |
14976 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
20 ms |
14684 KB |
Output is correct |
13 |
Correct |
195 ms |
15196 KB |
Output is correct |
14 |
Correct |
153 ms |
15580 KB |
Output is correct |
15 |
Correct |
165 ms |
15440 KB |
Output is correct |
16 |
Runtime error |
52 ms |
39508 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
8 ms |
14940 KB |
Output is correct |
5 |
Correct |
16 ms |
15452 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14852 KB |
Output is correct |
8 |
Correct |
17 ms |
14924 KB |
Output is correct |
9 |
Correct |
563 ms |
17316 KB |
Output is correct |
10 |
Correct |
51 ms |
42580 KB |
Output is correct |
11 |
Correct |
10 ms |
14940 KB |
Output is correct |
12 |
Correct |
181 ms |
15596 KB |
Output is correct |
13 |
Runtime error |
87 ms |
85332 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |