# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1001163 |
2024-06-18T16:14:02 Z |
De3b0o |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
1048576 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];
vector<ll> path[120009];
set<ll> pas[120009];
ll pr[120009];
ll o[120009];
vector<ll> g[120009];
ll vs;
ll vis[120009];
void ddfs(ll x)
{
if(vis[x])
return;
vis[x]=1;
vs++;
for(auto it : g[x])
ddfs(it);
}
void dfs(ll x , ll p , ll f , ll s)
{
pr[x]=p;
if(x==f)
{
ll y = f;
while(y)
{
path[s].pb(y);
pas[s].in(y);
y=pr[y];
}
reverse(path[s].begin(),path[s].end());
return;
}
for(auto it : adj[x])
{
if(it==p)
continue;
dfs(it,x,f,s);
}
}
int main()
{
d3
ll t;
cin >> t;
while(t--)
{
cin >> n;
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);
}
cin >> m;
for(int i = 1 ; m>=i ; i++)
{
cin >> S[i] >> T[i];
path[i].clear();
pas[i].clear();
g[i].clear();
o[i]=0;
dfs(S[i],0,T[i],i);
}
bool ans = 0;
for(int i = 1 ; m>=i ; i++)
{
for(int j = 1 ; m>=j ; j++)
{
if(i==j)
continue;
if(pas[i].find(S[j])==pas[i].end()&&pas[j].find(T[i])==pas[j].end())
{
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
}
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:92:14: warning: unused variable 'ans' [-Wunused-variable]
92 | bool ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18536 KB |
Output is correct |
2 |
Correct |
4 ms |
18496 KB |
Output is correct |
3 |
Correct |
4 ms |
18484 KB |
Output is correct |
4 |
Correct |
20 ms |
19036 KB |
Output is correct |
5 |
Correct |
39 ms |
19280 KB |
Output is correct |
6 |
Correct |
6 ms |
18780 KB |
Output is correct |
7 |
Correct |
6 ms |
18780 KB |
Output is correct |
8 |
Correct |
16 ms |
19804 KB |
Output is correct |
9 |
Correct |
1918 ms |
176724 KB |
Output is correct |
10 |
Runtime error |
2959 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18520 KB |
Output is correct |
2 |
Correct |
4 ms |
18524 KB |
Output is correct |
3 |
Correct |
5 ms |
18780 KB |
Output is correct |
4 |
Correct |
9 ms |
18780 KB |
Output is correct |
5 |
Correct |
10 ms |
18792 KB |
Output is correct |
6 |
Correct |
6 ms |
18788 KB |
Output is correct |
7 |
Correct |
5 ms |
18780 KB |
Output is correct |
8 |
Correct |
8 ms |
18776 KB |
Output is correct |
9 |
Correct |
6 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18520 KB |
Output is correct |
13 |
Correct |
5 ms |
18524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18520 KB |
Output is correct |
2 |
Correct |
4 ms |
18524 KB |
Output is correct |
3 |
Correct |
5 ms |
18780 KB |
Output is correct |
4 |
Correct |
9 ms |
18780 KB |
Output is correct |
5 |
Correct |
10 ms |
18792 KB |
Output is correct |
6 |
Correct |
6 ms |
18788 KB |
Output is correct |
7 |
Correct |
5 ms |
18780 KB |
Output is correct |
8 |
Correct |
8 ms |
18776 KB |
Output is correct |
9 |
Correct |
6 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18520 KB |
Output is correct |
13 |
Correct |
5 ms |
18524 KB |
Output is correct |
14 |
Correct |
5 ms |
18524 KB |
Output is correct |
15 |
Correct |
4 ms |
18524 KB |
Output is correct |
16 |
Correct |
5 ms |
18736 KB |
Output is correct |
17 |
Correct |
5 ms |
18568 KB |
Output is correct |
18 |
Correct |
6 ms |
18780 KB |
Output is correct |
19 |
Correct |
5 ms |
18524 KB |
Output is correct |
20 |
Correct |
6 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
5 ms |
18780 KB |
Output is correct |
23 |
Correct |
6 ms |
18524 KB |
Output is correct |
24 |
Correct |
5 ms |
18516 KB |
Output is correct |
25 |
Correct |
6 ms |
18772 KB |
Output is correct |
26 |
Correct |
5 ms |
18776 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18520 KB |
Output is correct |
2 |
Correct |
4 ms |
18524 KB |
Output is correct |
3 |
Correct |
5 ms |
18780 KB |
Output is correct |
4 |
Correct |
9 ms |
18780 KB |
Output is correct |
5 |
Correct |
10 ms |
18792 KB |
Output is correct |
6 |
Correct |
6 ms |
18788 KB |
Output is correct |
7 |
Correct |
5 ms |
18780 KB |
Output is correct |
8 |
Correct |
8 ms |
18776 KB |
Output is correct |
9 |
Correct |
6 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18520 KB |
Output is correct |
13 |
Correct |
5 ms |
18524 KB |
Output is correct |
14 |
Correct |
5 ms |
18524 KB |
Output is correct |
15 |
Correct |
4 ms |
18524 KB |
Output is correct |
16 |
Correct |
5 ms |
18736 KB |
Output is correct |
17 |
Correct |
5 ms |
18568 KB |
Output is correct |
18 |
Correct |
6 ms |
18780 KB |
Output is correct |
19 |
Correct |
5 ms |
18524 KB |
Output is correct |
20 |
Correct |
6 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
5 ms |
18780 KB |
Output is correct |
23 |
Correct |
6 ms |
18524 KB |
Output is correct |
24 |
Correct |
5 ms |
18516 KB |
Output is correct |
25 |
Correct |
6 ms |
18772 KB |
Output is correct |
26 |
Correct |
5 ms |
18776 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18524 KB |
Output is correct |
29 |
Correct |
16 ms |
19804 KB |
Output is correct |
30 |
Correct |
10 ms |
18780 KB |
Output is correct |
31 |
Correct |
13 ms |
19036 KB |
Output is correct |
32 |
Correct |
10 ms |
18780 KB |
Output is correct |
33 |
Correct |
6 ms |
18780 KB |
Output is correct |
34 |
Correct |
11 ms |
18976 KB |
Output is correct |
35 |
Correct |
19 ms |
19292 KB |
Output is correct |
36 |
Correct |
10 ms |
18932 KB |
Output is correct |
37 |
Correct |
10 ms |
18872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18520 KB |
Output is correct |
2 |
Correct |
4 ms |
18524 KB |
Output is correct |
3 |
Correct |
5 ms |
18780 KB |
Output is correct |
4 |
Correct |
9 ms |
18780 KB |
Output is correct |
5 |
Correct |
10 ms |
18792 KB |
Output is correct |
6 |
Correct |
6 ms |
18788 KB |
Output is correct |
7 |
Correct |
5 ms |
18780 KB |
Output is correct |
8 |
Correct |
8 ms |
18776 KB |
Output is correct |
9 |
Correct |
6 ms |
18776 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18520 KB |
Output is correct |
13 |
Correct |
5 ms |
18524 KB |
Output is correct |
14 |
Correct |
5 ms |
18524 KB |
Output is correct |
15 |
Correct |
4 ms |
18524 KB |
Output is correct |
16 |
Correct |
5 ms |
18736 KB |
Output is correct |
17 |
Correct |
5 ms |
18568 KB |
Output is correct |
18 |
Correct |
6 ms |
18780 KB |
Output is correct |
19 |
Correct |
5 ms |
18524 KB |
Output is correct |
20 |
Correct |
6 ms |
18780 KB |
Output is correct |
21 |
Correct |
5 ms |
18780 KB |
Output is correct |
22 |
Correct |
5 ms |
18780 KB |
Output is correct |
23 |
Correct |
6 ms |
18524 KB |
Output is correct |
24 |
Correct |
5 ms |
18516 KB |
Output is correct |
25 |
Correct |
6 ms |
18772 KB |
Output is correct |
26 |
Correct |
5 ms |
18776 KB |
Output is correct |
27 |
Correct |
5 ms |
18780 KB |
Output is correct |
28 |
Correct |
5 ms |
18524 KB |
Output is correct |
29 |
Correct |
16 ms |
19804 KB |
Output is correct |
30 |
Correct |
10 ms |
18780 KB |
Output is correct |
31 |
Correct |
13 ms |
19036 KB |
Output is correct |
32 |
Correct |
10 ms |
18780 KB |
Output is correct |
33 |
Correct |
6 ms |
18780 KB |
Output is correct |
34 |
Correct |
11 ms |
18976 KB |
Output is correct |
35 |
Correct |
19 ms |
19292 KB |
Output is correct |
36 |
Correct |
10 ms |
18932 KB |
Output is correct |
37 |
Correct |
10 ms |
18872 KB |
Output is correct |
38 |
Correct |
2033 ms |
176776 KB |
Output is correct |
39 |
Runtime error |
2873 ms |
1048576 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18520 KB |
Output is correct |
2 |
Correct |
4 ms |
18524 KB |
Output is correct |
3 |
Correct |
5 ms |
18728 KB |
Output is correct |
4 |
Correct |
4 ms |
18712 KB |
Output is correct |
5 |
Correct |
29 ms |
18780 KB |
Output is correct |
6 |
Correct |
5 ms |
18524 KB |
Output is correct |
7 |
Correct |
6 ms |
18524 KB |
Output is correct |
8 |
Correct |
5 ms |
18520 KB |
Output is correct |
9 |
Correct |
5 ms |
18524 KB |
Output is correct |
10 |
Correct |
5 ms |
18516 KB |
Output is correct |
11 |
Correct |
5 ms |
18524 KB |
Output is correct |
12 |
Correct |
10 ms |
18780 KB |
Output is correct |
13 |
Correct |
107 ms |
19304 KB |
Output is correct |
14 |
Correct |
88 ms |
19652 KB |
Output is correct |
15 |
Correct |
88 ms |
19436 KB |
Output is correct |
16 |
Execution timed out |
5052 ms |
27064 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18536 KB |
Output is correct |
2 |
Correct |
4 ms |
18496 KB |
Output is correct |
3 |
Correct |
4 ms |
18484 KB |
Output is correct |
4 |
Correct |
20 ms |
19036 KB |
Output is correct |
5 |
Correct |
39 ms |
19280 KB |
Output is correct |
6 |
Correct |
6 ms |
18780 KB |
Output is correct |
7 |
Correct |
6 ms |
18780 KB |
Output is correct |
8 |
Correct |
16 ms |
19804 KB |
Output is correct |
9 |
Correct |
1918 ms |
176724 KB |
Output is correct |
10 |
Runtime error |
2959 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |