# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874459 |
2023-11-17T05:12:27 Z |
winter0101 |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
33112 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 st[maxn][19];
int d[maxn];
void dfs(int u,int par){
for (auto v:a[u]){
if (v==par)continue;
st[v][0]=u;
for1(i,1,17)st[v][i]=st[st[v][i-1]][i-1];
d[v]=d[u]+1;
dfs(v,u);
}
}
int lca(int u,int v){
if (d[u]<d[v])swap(u,v);
int k=d[u]-d[v];
for1(i,0,17)if (k>>i&1)u=st[u][i];
if (u==v)return u;
for2(i,17,0){
if (!st[u][i]||!st[v][i])continue;
if (st[u][i]!=st[v][i]){
u=st[u][i];
v=st[v][i];
}
}
return st[u][0];
}
bool onpath(int u,int v,int k){
int t=lca(u,v);
if (lca(t,k)==t&&lca(k,u)==k)return 1;
if (lca(t,k)==t&&lca(k,v)==k)return 1;
return 0;
}
vector<int>g[maxn];
int scc=0;
int low[maxn],num[maxn],tme=0;
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]){
scc++;
while (!t.empty()&&t.top()!=u){
num[t.top()]=-1;
t.pop();
}
num[u]=-1;
t.pop();
}
}
void solve(){
int n;
cin>>n;
for1(i,1,n){
a[i].clear();
g[i].clear();
}
for1(i,1,n-1){
int u,v;
cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
for1(i,0,17)for1(j,1,n)st[j][i]=0;
dfs(1,0);
int m;
cin>>m;
for1(i,1,m){
low[i]=num[i]=0;
cin>>b[i].fi>>b[i].se;
}
for1(i,1,m){
for1(j,1,m){
if (i==j)continue;
if (onpath(b[i].fi,b[i].se,b[j].fi)){
g[j].pb(i);
//cout<<j<<" "<<i<<'\n';
}
if (onpath(b[i].fi,b[i].se,b[j].se)){
g[i].pb(j);
//cout<<i<<" "<<j<<'\n';
}
}
}
scc=tme=0;
for1(i,1,m)if (!num[i])redfs(i);
//cout<<low[1]<<" "<<num[1]<<" "<<low[2]<<" "<<num[2];
if (scc==m)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;
cin>>test;
while (test--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
13 ms |
9000 KB |
Output is correct |
5 |
Correct |
22 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
50 ms |
9072 KB |
Output is correct |
9 |
Correct |
1612 ms |
13872 KB |
Output is correct |
10 |
Correct |
133 ms |
31616 KB |
Output is correct |
11 |
Correct |
16 ms |
8796 KB |
Output is correct |
12 |
Correct |
496 ms |
9076 KB |
Output is correct |
13 |
Execution timed out |
5022 ms |
30756 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8980 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8980 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9000 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8988 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
3 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
3 ms |
8796 KB |
Output is correct |
21 |
Correct |
3 ms |
8880 KB |
Output is correct |
22 |
Correct |
3 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
2 ms |
8992 KB |
Output is correct |
27 |
Correct |
4 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8980 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9000 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8988 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
3 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
3 ms |
8796 KB |
Output is correct |
21 |
Correct |
3 ms |
8880 KB |
Output is correct |
22 |
Correct |
3 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
2 ms |
8992 KB |
Output is correct |
27 |
Correct |
4 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
29 |
Correct |
45 ms |
9052 KB |
Output is correct |
30 |
Correct |
26 ms |
9048 KB |
Output is correct |
31 |
Correct |
28 ms |
9148 KB |
Output is correct |
32 |
Correct |
17 ms |
8796 KB |
Output is correct |
33 |
Correct |
5 ms |
9044 KB |
Output is correct |
34 |
Correct |
55 ms |
9028 KB |
Output is correct |
35 |
Correct |
73 ms |
9052 KB |
Output is correct |
36 |
Correct |
40 ms |
9032 KB |
Output is correct |
37 |
Correct |
26 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8980 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
3 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
3 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9000 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8988 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
3 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
3 ms |
8796 KB |
Output is correct |
21 |
Correct |
3 ms |
8880 KB |
Output is correct |
22 |
Correct |
3 ms |
9052 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
2 ms |
8992 KB |
Output is correct |
27 |
Correct |
4 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
29 |
Correct |
45 ms |
9052 KB |
Output is correct |
30 |
Correct |
26 ms |
9048 KB |
Output is correct |
31 |
Correct |
28 ms |
9148 KB |
Output is correct |
32 |
Correct |
17 ms |
8796 KB |
Output is correct |
33 |
Correct |
5 ms |
9044 KB |
Output is correct |
34 |
Correct |
55 ms |
9028 KB |
Output is correct |
35 |
Correct |
73 ms |
9052 KB |
Output is correct |
36 |
Correct |
40 ms |
9032 KB |
Output is correct |
37 |
Correct |
26 ms |
8796 KB |
Output is correct |
38 |
Correct |
1584 ms |
14676 KB |
Output is correct |
39 |
Correct |
135 ms |
33112 KB |
Output is correct |
40 |
Correct |
1747 ms |
13728 KB |
Output is correct |
41 |
Correct |
1351 ms |
12764 KB |
Output is correct |
42 |
Correct |
1295 ms |
13908 KB |
Output is correct |
43 |
Correct |
40 ms |
12412 KB |
Output is correct |
44 |
Correct |
1267 ms |
11880 KB |
Output is correct |
45 |
Correct |
159 ms |
22364 KB |
Output is correct |
46 |
Correct |
167 ms |
22616 KB |
Output is correct |
47 |
Correct |
209 ms |
27052 KB |
Output is correct |
48 |
Correct |
196 ms |
26860 KB |
Output is correct |
49 |
Correct |
184 ms |
22364 KB |
Output is correct |
50 |
Correct |
185 ms |
22600 KB |
Output is correct |
51 |
Correct |
58 ms |
23824 KB |
Output is correct |
52 |
Correct |
54 ms |
23900 KB |
Output is correct |
53 |
Correct |
920 ms |
11596 KB |
Output is correct |
54 |
Correct |
124 ms |
22360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8948 KB |
Output is correct |
5 |
Correct |
17 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
40 ms |
8796 KB |
Output is correct |
13 |
Correct |
506 ms |
9532 KB |
Output is correct |
14 |
Correct |
245 ms |
9760 KB |
Output is correct |
15 |
Correct |
435 ms |
9824 KB |
Output is correct |
16 |
Execution timed out |
5009 ms |
22928 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
13 ms |
9000 KB |
Output is correct |
5 |
Correct |
22 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
50 ms |
9072 KB |
Output is correct |
9 |
Correct |
1612 ms |
13872 KB |
Output is correct |
10 |
Correct |
133 ms |
31616 KB |
Output is correct |
11 |
Correct |
16 ms |
8796 KB |
Output is correct |
12 |
Correct |
496 ms |
9076 KB |
Output is correct |
13 |
Execution timed out |
5022 ms |
30756 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |