# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1001282 |
2024-06-18T18:05:47 Z |
De3b0o |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
313984 KB |
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)
using namespace std;
ll n , m;
vector<ll> adj[120009];
ll S[120009] , T[120009];
ll o[120009];
vector<ll> g[120009];
ll vs;
ll vis[120009];
set<pll> seg[2000009];
ll et[250009];
ll ti[120009] , to[120009];
ll timer;
ll depth[120009];
void ett(ll x , ll p , ll de)
{
depth[x]=de;
et[timer]=x;
ti[x]=timer;
timer++;
for(auto it : adj[x])
{
if(it==p)
continue;
ett(it,x,de+1);
}
et[timer]=x;
to[x]=timer;
timer++;
}
void ddfs(ll x)
{
if(vis[x])
return;
vis[x]=1;
vs++;
for(auto it : g[x])
ddfs(it);
}
void se(ll x , ll l , ll r , ll idx , ll val1 , ll val2)
{
if(l>idx||r<idx)
return;
seg[x].in({val1,val2});
if(l!=r)
{
se(lc,l,mid,idx,val1,val2);
se(rc,mid+1,r,idx,val1,val2);
}
}
pll sg(ll x , ll l , ll r , ll l1 , ll r1 , ll idx)
{
if(l>r1||r<l1)
return {1e18,-1};
if(l>=l1&&r<=r1)
{
auto it = seg[x].lower_bound({idx,0});
if(it!=seg[x].end())
return *it;
else
return {1e18,-1};
}
pll le = sg(lc,l,mid,l1,r1,idx);
pll ri = sg(rc,mid+1,r,l1,r1,idx);
if(le.F>ri.F)
return ri;
else
return le;
}
ll lca(ll u , ll v)
{
pll x = sg(1,0,2*n-1,0,min(ti[u],ti[v]),max(ti[u],ti[v]));
return x.S;
}
bool inpath(ll x , ll u , ll v)
{
bool ans = 1;
if((lca(x,u)==x||lca(x,v)==x)&&depth[x]>=depth[lca(u,v)])
ans=0;
return ans;
}
int main()
{
d3
ll t;
cin >> t;
while(t--)
{
cin >> n;
for(int i = 0 ; 16*n>=i ; i++)
seg[i].clear();
for(int i = 1 ; n>=i ; i++)
adj[i].clear();
for(int i = 0 ; n-1>i ; i++)
{
ll u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
timer=0;
ett(1,0,0);
for(int i = 1 ; n>=i ; i++)
{
se(1,0,2*n-1,ti[i],to[i],i);
}
cin >> m;
for(int i = 1 ; m>=i ; i++)
{
cin >> S[i] >> T[i];
g[i].clear();
o[i]=0;
}
for(int i = 1 ; m>=i ; i++)
{
for(int j = 1 ; m>=j ; j++)
{
if(i==j)
continue;
//cout << inpath(S[j],S[i],T[i]) << " " << inpath(T[i],S[j],T[j]) << "\n";
if(inpath(S[j],S[i],T[i])&&inpath(T[i],S[j],T[j]))
{
g[j].pb(i);
o[i]++;
}
}
}
ll x = 0;
ll v[120009] = {0};
while(true)
{
ll y = 0;
vector<ll> d;
for(int i = 1 ; m>=i ; i++)
{
if(v[i])
continue;
if(o[i]==m-x-1)
{
v[i]=1;
d.pb(i);
y++;
}
}
if(!y)
break;
x+=y;
for(auto it : d)
{
for(auto it1 : g[it])
o[it1]--;
}
}
if(x==m)
yes
else
no
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
102996 KB |
Output is correct |
2 |
Correct |
33 ms |
102992 KB |
Output is correct |
3 |
Correct |
42 ms |
102996 KB |
Output is correct |
4 |
Correct |
64 ms |
103260 KB |
Output is correct |
5 |
Correct |
99 ms |
103260 KB |
Output is correct |
6 |
Correct |
36 ms |
103260 KB |
Output is correct |
7 |
Correct |
37 ms |
103244 KB |
Output is correct |
8 |
Correct |
106 ms |
103492 KB |
Output is correct |
9 |
Correct |
4188 ms |
111572 KB |
Output is correct |
10 |
Correct |
752 ms |
261972 KB |
Output is correct |
11 |
Correct |
64 ms |
102992 KB |
Output is correct |
12 |
Correct |
578 ms |
103248 KB |
Output is correct |
13 |
Execution timed out |
5114 ms |
313984 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
103004 KB |
Output is correct |
2 |
Correct |
37 ms |
103112 KB |
Output is correct |
3 |
Correct |
42 ms |
103248 KB |
Output is correct |
4 |
Correct |
44 ms |
103260 KB |
Output is correct |
5 |
Correct |
43 ms |
103416 KB |
Output is correct |
6 |
Correct |
43 ms |
103252 KB |
Output is correct |
7 |
Correct |
44 ms |
103248 KB |
Output is correct |
8 |
Correct |
42 ms |
103260 KB |
Output is correct |
9 |
Correct |
41 ms |
103180 KB |
Output is correct |
10 |
Correct |
41 ms |
103252 KB |
Output is correct |
11 |
Correct |
42 ms |
103252 KB |
Output is correct |
12 |
Correct |
38 ms |
103124 KB |
Output is correct |
13 |
Correct |
40 ms |
103248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
103004 KB |
Output is correct |
2 |
Correct |
37 ms |
103112 KB |
Output is correct |
3 |
Correct |
42 ms |
103248 KB |
Output is correct |
4 |
Correct |
44 ms |
103260 KB |
Output is correct |
5 |
Correct |
43 ms |
103416 KB |
Output is correct |
6 |
Correct |
43 ms |
103252 KB |
Output is correct |
7 |
Correct |
44 ms |
103248 KB |
Output is correct |
8 |
Correct |
42 ms |
103260 KB |
Output is correct |
9 |
Correct |
41 ms |
103180 KB |
Output is correct |
10 |
Correct |
41 ms |
103252 KB |
Output is correct |
11 |
Correct |
42 ms |
103252 KB |
Output is correct |
12 |
Correct |
38 ms |
103124 KB |
Output is correct |
13 |
Correct |
40 ms |
103248 KB |
Output is correct |
14 |
Correct |
36 ms |
103128 KB |
Output is correct |
15 |
Correct |
41 ms |
102996 KB |
Output is correct |
16 |
Correct |
41 ms |
103408 KB |
Output is correct |
17 |
Correct |
42 ms |
103252 KB |
Output is correct |
18 |
Correct |
41 ms |
103260 KB |
Output is correct |
19 |
Correct |
37 ms |
102988 KB |
Output is correct |
20 |
Correct |
40 ms |
103328 KB |
Output is correct |
21 |
Correct |
42 ms |
103252 KB |
Output is correct |
22 |
Correct |
40 ms |
103248 KB |
Output is correct |
23 |
Correct |
38 ms |
103000 KB |
Output is correct |
24 |
Correct |
36 ms |
103256 KB |
Output is correct |
25 |
Correct |
42 ms |
103256 KB |
Output is correct |
26 |
Correct |
38 ms |
103248 KB |
Output is correct |
27 |
Correct |
41 ms |
103260 KB |
Output is correct |
28 |
Correct |
37 ms |
103004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
103004 KB |
Output is correct |
2 |
Correct |
37 ms |
103112 KB |
Output is correct |
3 |
Correct |
42 ms |
103248 KB |
Output is correct |
4 |
Correct |
44 ms |
103260 KB |
Output is correct |
5 |
Correct |
43 ms |
103416 KB |
Output is correct |
6 |
Correct |
43 ms |
103252 KB |
Output is correct |
7 |
Correct |
44 ms |
103248 KB |
Output is correct |
8 |
Correct |
42 ms |
103260 KB |
Output is correct |
9 |
Correct |
41 ms |
103180 KB |
Output is correct |
10 |
Correct |
41 ms |
103252 KB |
Output is correct |
11 |
Correct |
42 ms |
103252 KB |
Output is correct |
12 |
Correct |
38 ms |
103124 KB |
Output is correct |
13 |
Correct |
40 ms |
103248 KB |
Output is correct |
14 |
Correct |
36 ms |
103128 KB |
Output is correct |
15 |
Correct |
41 ms |
102996 KB |
Output is correct |
16 |
Correct |
41 ms |
103408 KB |
Output is correct |
17 |
Correct |
42 ms |
103252 KB |
Output is correct |
18 |
Correct |
41 ms |
103260 KB |
Output is correct |
19 |
Correct |
37 ms |
102988 KB |
Output is correct |
20 |
Correct |
40 ms |
103328 KB |
Output is correct |
21 |
Correct |
42 ms |
103252 KB |
Output is correct |
22 |
Correct |
40 ms |
103248 KB |
Output is correct |
23 |
Correct |
38 ms |
103000 KB |
Output is correct |
24 |
Correct |
36 ms |
103256 KB |
Output is correct |
25 |
Correct |
42 ms |
103256 KB |
Output is correct |
26 |
Correct |
38 ms |
103248 KB |
Output is correct |
27 |
Correct |
41 ms |
103260 KB |
Output is correct |
28 |
Correct |
37 ms |
103004 KB |
Output is correct |
29 |
Correct |
85 ms |
103540 KB |
Output is correct |
30 |
Correct |
61 ms |
103508 KB |
Output is correct |
31 |
Correct |
66 ms |
103504 KB |
Output is correct |
32 |
Correct |
52 ms |
103248 KB |
Output is correct |
33 |
Correct |
43 ms |
103252 KB |
Output is correct |
34 |
Correct |
82 ms |
103488 KB |
Output is correct |
35 |
Correct |
82 ms |
103492 KB |
Output is correct |
36 |
Correct |
80 ms |
103280 KB |
Output is correct |
37 |
Correct |
70 ms |
103508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
103004 KB |
Output is correct |
2 |
Correct |
37 ms |
103112 KB |
Output is correct |
3 |
Correct |
42 ms |
103248 KB |
Output is correct |
4 |
Correct |
44 ms |
103260 KB |
Output is correct |
5 |
Correct |
43 ms |
103416 KB |
Output is correct |
6 |
Correct |
43 ms |
103252 KB |
Output is correct |
7 |
Correct |
44 ms |
103248 KB |
Output is correct |
8 |
Correct |
42 ms |
103260 KB |
Output is correct |
9 |
Correct |
41 ms |
103180 KB |
Output is correct |
10 |
Correct |
41 ms |
103252 KB |
Output is correct |
11 |
Correct |
42 ms |
103252 KB |
Output is correct |
12 |
Correct |
38 ms |
103124 KB |
Output is correct |
13 |
Correct |
40 ms |
103248 KB |
Output is correct |
14 |
Correct |
36 ms |
103128 KB |
Output is correct |
15 |
Correct |
41 ms |
102996 KB |
Output is correct |
16 |
Correct |
41 ms |
103408 KB |
Output is correct |
17 |
Correct |
42 ms |
103252 KB |
Output is correct |
18 |
Correct |
41 ms |
103260 KB |
Output is correct |
19 |
Correct |
37 ms |
102988 KB |
Output is correct |
20 |
Correct |
40 ms |
103328 KB |
Output is correct |
21 |
Correct |
42 ms |
103252 KB |
Output is correct |
22 |
Correct |
40 ms |
103248 KB |
Output is correct |
23 |
Correct |
38 ms |
103000 KB |
Output is correct |
24 |
Correct |
36 ms |
103256 KB |
Output is correct |
25 |
Correct |
42 ms |
103256 KB |
Output is correct |
26 |
Correct |
38 ms |
103248 KB |
Output is correct |
27 |
Correct |
41 ms |
103260 KB |
Output is correct |
28 |
Correct |
37 ms |
103004 KB |
Output is correct |
29 |
Correct |
85 ms |
103540 KB |
Output is correct |
30 |
Correct |
61 ms |
103508 KB |
Output is correct |
31 |
Correct |
66 ms |
103504 KB |
Output is correct |
32 |
Correct |
52 ms |
103248 KB |
Output is correct |
33 |
Correct |
43 ms |
103252 KB |
Output is correct |
34 |
Correct |
82 ms |
103488 KB |
Output is correct |
35 |
Correct |
82 ms |
103492 KB |
Output is correct |
36 |
Correct |
80 ms |
103280 KB |
Output is correct |
37 |
Correct |
70 ms |
103508 KB |
Output is correct |
38 |
Correct |
3874 ms |
112584 KB |
Output is correct |
39 |
Correct |
688 ms |
263508 KB |
Output is correct |
40 |
Correct |
3253 ms |
112628 KB |
Output is correct |
41 |
Correct |
2654 ms |
112468 KB |
Output is correct |
42 |
Correct |
3026 ms |
112792 KB |
Output is correct |
43 |
Correct |
240 ms |
110420 KB |
Output is correct |
44 |
Correct |
1480 ms |
106316 KB |
Output is correct |
45 |
Correct |
1118 ms |
257364 KB |
Output is correct |
46 |
Correct |
1226 ms |
259412 KB |
Output is correct |
47 |
Correct |
1263 ms |
260948 KB |
Output is correct |
48 |
Correct |
1241 ms |
260948 KB |
Output is correct |
49 |
Correct |
1062 ms |
257364 KB |
Output is correct |
50 |
Correct |
1098 ms |
257280 KB |
Output is correct |
51 |
Correct |
837 ms |
259020 KB |
Output is correct |
52 |
Correct |
771 ms |
256808 KB |
Output is correct |
53 |
Correct |
1330 ms |
114004 KB |
Output is correct |
54 |
Correct |
1392 ms |
258032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
103248 KB |
Output is correct |
2 |
Correct |
36 ms |
103004 KB |
Output is correct |
3 |
Correct |
35 ms |
103004 KB |
Output is correct |
4 |
Correct |
34 ms |
102992 KB |
Output is correct |
5 |
Correct |
69 ms |
103256 KB |
Output is correct |
6 |
Correct |
40 ms |
103248 KB |
Output is correct |
7 |
Correct |
37 ms |
103240 KB |
Output is correct |
8 |
Correct |
39 ms |
103000 KB |
Output is correct |
9 |
Correct |
37 ms |
102992 KB |
Output is correct |
10 |
Correct |
38 ms |
103100 KB |
Output is correct |
11 |
Correct |
37 ms |
103004 KB |
Output is correct |
12 |
Correct |
74 ms |
103256 KB |
Output is correct |
13 |
Correct |
458 ms |
103800 KB |
Output is correct |
14 |
Correct |
298 ms |
104020 KB |
Output is correct |
15 |
Correct |
396 ms |
103760 KB |
Output is correct |
16 |
Execution timed out |
5044 ms |
296280 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
102996 KB |
Output is correct |
2 |
Correct |
33 ms |
102992 KB |
Output is correct |
3 |
Correct |
42 ms |
102996 KB |
Output is correct |
4 |
Correct |
64 ms |
103260 KB |
Output is correct |
5 |
Correct |
99 ms |
103260 KB |
Output is correct |
6 |
Correct |
36 ms |
103260 KB |
Output is correct |
7 |
Correct |
37 ms |
103244 KB |
Output is correct |
8 |
Correct |
106 ms |
103492 KB |
Output is correct |
9 |
Correct |
4188 ms |
111572 KB |
Output is correct |
10 |
Correct |
752 ms |
261972 KB |
Output is correct |
11 |
Correct |
64 ms |
102992 KB |
Output is correct |
12 |
Correct |
578 ms |
103248 KB |
Output is correct |
13 |
Execution timed out |
5114 ms |
313984 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |