# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
552132 |
2022-04-22T13:20:38 Z |
errorgorn |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
36684 KB |
// Super Idol的笑容
// 都没你的甜
// 八月正午的阳光
// 都没你耀眼
// 热爱105°C的你
// 滴滴清纯的蒸馏水
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,q;
vector<int> al[120005];
ii arr[120005];
int d[120005];
int tkd[120005][19];
void dfs(int i,int p){
for (auto it:al[i]){
if (it==p) continue;
d[it]=d[i]+1;
int curr=tkd[it][0]=i;
rep(x,0,19){
if (curr==-1) continue;
curr=tkd[it][x+1]=tkd[curr][x];
}
dfs(it,i);
}
}
int mov(int i,int k){
rep(x,0,19) if (k&(1<<x)) i=tkd[i][x];
return i;
}
int lca(int i,int j){
if (d[i]<d[j]) swap(i,j);
i=mov(i,d[i]-d[j]);
if (i==j) return i;
rep(x,19,0) if (tkd[i][x]!=tkd[j][x]){
i=tkd[i][x];
j=tkd[j][x];
}
return tkd[i][0];
}
int dist(int i,int j){
int g=lca(i,j);
return d[i]+d[j]-2*d[g];
}
int vis[120005];
bool cyc;
void dfs2(int i){
vis[i]=1;
for (auto it:al[i]){
if (vis[it]==1) cyc=true;
if (vis[it]==0) dfs2(it);
}
vis[i]=2;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
int TC;
cin>>TC;
while (TC--){
cin>>n;
rep(x,1,n+1) al[x].clear();
int a,b;
rep(x,1,n){
cin>>a>>b;
al[a].pub(b);
al[b].pub(a);
}
rep(x,1,n+1) rep(y,0,19) tkd[x][y]=-1;
dfs(1,-1);
cin>>q;
rep(x,0,q){
cin>>a>>b;
arr[x]={a,b};
}
rep(x,0,q) al[x].clear();
rep(x,0,q) rep(y,0,q) if (x!=y){
//must we put x before y
int d=dist(arr[x].fi,arr[x].se);
if (dist(arr[x].fi,arr[y].fi)+dist(arr[y].fi,arr[x].se)==d){
al[x].pub(y);
}
if (dist(arr[x].fi,arr[y].se)+dist(arr[y].se,arr[x].se)==d){
al[y].pub(x);
}
}
cyc=false;
rep(x,0,q) vis[x]=0;
rep(x,0,q) if (vis[x]==0) dfs2(x);
if (!cyc) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
13 ms |
3284 KB |
Output is correct |
5 |
Correct |
20 ms |
3320 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3156 KB |
Output is correct |
8 |
Correct |
53 ms |
3360 KB |
Output is correct |
9 |
Correct |
1504 ms |
9096 KB |
Output is correct |
10 |
Correct |
137 ms |
36172 KB |
Output is correct |
11 |
Correct |
20 ms |
3284 KB |
Output is correct |
12 |
Correct |
511 ms |
3988 KB |
Output is correct |
13 |
Execution timed out |
5025 ms |
34848 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
3156 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3160 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3156 KB |
Output is correct |
11 |
Correct |
3 ms |
3156 KB |
Output is correct |
12 |
Correct |
3 ms |
3156 KB |
Output is correct |
13 |
Correct |
3 ms |
3236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
3156 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3160 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3156 KB |
Output is correct |
11 |
Correct |
3 ms |
3156 KB |
Output is correct |
12 |
Correct |
3 ms |
3156 KB |
Output is correct |
13 |
Correct |
3 ms |
3236 KB |
Output is correct |
14 |
Correct |
2 ms |
3156 KB |
Output is correct |
15 |
Correct |
2 ms |
3156 KB |
Output is correct |
16 |
Correct |
3 ms |
3156 KB |
Output is correct |
17 |
Correct |
3 ms |
3156 KB |
Output is correct |
18 |
Correct |
3 ms |
3156 KB |
Output is correct |
19 |
Correct |
2 ms |
3144 KB |
Output is correct |
20 |
Correct |
3 ms |
3152 KB |
Output is correct |
21 |
Correct |
4 ms |
3156 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
2 ms |
3156 KB |
Output is correct |
24 |
Correct |
2 ms |
3156 KB |
Output is correct |
25 |
Correct |
4 ms |
3156 KB |
Output is correct |
26 |
Correct |
3 ms |
3148 KB |
Output is correct |
27 |
Correct |
3 ms |
3156 KB |
Output is correct |
28 |
Correct |
2 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
3156 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3160 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3156 KB |
Output is correct |
11 |
Correct |
3 ms |
3156 KB |
Output is correct |
12 |
Correct |
3 ms |
3156 KB |
Output is correct |
13 |
Correct |
3 ms |
3236 KB |
Output is correct |
14 |
Correct |
2 ms |
3156 KB |
Output is correct |
15 |
Correct |
2 ms |
3156 KB |
Output is correct |
16 |
Correct |
3 ms |
3156 KB |
Output is correct |
17 |
Correct |
3 ms |
3156 KB |
Output is correct |
18 |
Correct |
3 ms |
3156 KB |
Output is correct |
19 |
Correct |
2 ms |
3144 KB |
Output is correct |
20 |
Correct |
3 ms |
3152 KB |
Output is correct |
21 |
Correct |
4 ms |
3156 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
2 ms |
3156 KB |
Output is correct |
24 |
Correct |
2 ms |
3156 KB |
Output is correct |
25 |
Correct |
4 ms |
3156 KB |
Output is correct |
26 |
Correct |
3 ms |
3148 KB |
Output is correct |
27 |
Correct |
3 ms |
3156 KB |
Output is correct |
28 |
Correct |
2 ms |
3156 KB |
Output is correct |
29 |
Correct |
62 ms |
3408 KB |
Output is correct |
30 |
Correct |
66 ms |
3264 KB |
Output is correct |
31 |
Correct |
58 ms |
3296 KB |
Output is correct |
32 |
Correct |
26 ms |
3220 KB |
Output is correct |
33 |
Correct |
7 ms |
3156 KB |
Output is correct |
34 |
Correct |
107 ms |
3384 KB |
Output is correct |
35 |
Correct |
112 ms |
3356 KB |
Output is correct |
36 |
Correct |
108 ms |
3196 KB |
Output is correct |
37 |
Correct |
59 ms |
3248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
3156 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3160 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3156 KB |
Output is correct |
11 |
Correct |
3 ms |
3156 KB |
Output is correct |
12 |
Correct |
3 ms |
3156 KB |
Output is correct |
13 |
Correct |
3 ms |
3236 KB |
Output is correct |
14 |
Correct |
2 ms |
3156 KB |
Output is correct |
15 |
Correct |
2 ms |
3156 KB |
Output is correct |
16 |
Correct |
3 ms |
3156 KB |
Output is correct |
17 |
Correct |
3 ms |
3156 KB |
Output is correct |
18 |
Correct |
3 ms |
3156 KB |
Output is correct |
19 |
Correct |
2 ms |
3144 KB |
Output is correct |
20 |
Correct |
3 ms |
3152 KB |
Output is correct |
21 |
Correct |
4 ms |
3156 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
2 ms |
3156 KB |
Output is correct |
24 |
Correct |
2 ms |
3156 KB |
Output is correct |
25 |
Correct |
4 ms |
3156 KB |
Output is correct |
26 |
Correct |
3 ms |
3148 KB |
Output is correct |
27 |
Correct |
3 ms |
3156 KB |
Output is correct |
28 |
Correct |
2 ms |
3156 KB |
Output is correct |
29 |
Correct |
62 ms |
3408 KB |
Output is correct |
30 |
Correct |
66 ms |
3264 KB |
Output is correct |
31 |
Correct |
58 ms |
3296 KB |
Output is correct |
32 |
Correct |
26 ms |
3220 KB |
Output is correct |
33 |
Correct |
7 ms |
3156 KB |
Output is correct |
34 |
Correct |
107 ms |
3384 KB |
Output is correct |
35 |
Correct |
112 ms |
3356 KB |
Output is correct |
36 |
Correct |
108 ms |
3196 KB |
Output is correct |
37 |
Correct |
59 ms |
3248 KB |
Output is correct |
38 |
Correct |
1593 ms |
9104 KB |
Output is correct |
39 |
Correct |
146 ms |
36684 KB |
Output is correct |
40 |
Correct |
2848 ms |
7812 KB |
Output is correct |
41 |
Correct |
2847 ms |
5720 KB |
Output is correct |
42 |
Correct |
2730 ms |
7960 KB |
Output is correct |
43 |
Correct |
51 ms |
5572 KB |
Output is correct |
44 |
Correct |
2623 ms |
4128 KB |
Output is correct |
45 |
Correct |
318 ms |
27664 KB |
Output is correct |
46 |
Correct |
312 ms |
27700 KB |
Output is correct |
47 |
Correct |
398 ms |
31184 KB |
Output is correct |
48 |
Correct |
411 ms |
31436 KB |
Output is correct |
49 |
Correct |
314 ms |
27848 KB |
Output is correct |
50 |
Correct |
325 ms |
27668 KB |
Output is correct |
51 |
Correct |
93 ms |
27776 KB |
Output is correct |
52 |
Correct |
104 ms |
28740 KB |
Output is correct |
53 |
Correct |
2380 ms |
4872 KB |
Output is correct |
54 |
Correct |
262 ms |
28272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
2 ms |
3148 KB |
Output is correct |
5 |
Correct |
19 ms |
3288 KB |
Output is correct |
6 |
Correct |
2 ms |
3156 KB |
Output is correct |
7 |
Correct |
2 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3148 KB |
Output is correct |
10 |
Correct |
2 ms |
3156 KB |
Output is correct |
11 |
Correct |
2 ms |
3156 KB |
Output is correct |
12 |
Correct |
103 ms |
3228 KB |
Output is correct |
13 |
Correct |
1083 ms |
3844 KB |
Output is correct |
14 |
Correct |
485 ms |
3964 KB |
Output is correct |
15 |
Correct |
818 ms |
3796 KB |
Output is correct |
16 |
Execution timed out |
5036 ms |
27752 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Correct |
13 ms |
3284 KB |
Output is correct |
5 |
Correct |
20 ms |
3320 KB |
Output is correct |
6 |
Correct |
3 ms |
3156 KB |
Output is correct |
7 |
Correct |
3 ms |
3156 KB |
Output is correct |
8 |
Correct |
53 ms |
3360 KB |
Output is correct |
9 |
Correct |
1504 ms |
9096 KB |
Output is correct |
10 |
Correct |
137 ms |
36172 KB |
Output is correct |
11 |
Correct |
20 ms |
3284 KB |
Output is correct |
12 |
Correct |
511 ms |
3988 KB |
Output is correct |
13 |
Execution timed out |
5025 ms |
34848 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |