답안 #758315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758315 2023-06-14T12:28:40 Z bachhoangxuan Jail (JOI22_jail) C++17
100 / 100
3064 ms 617808 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=120005;
const int bl=650;
const int maxs=650;
const int maxm=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;
void solve(){
    int cur,cnt,n;cin >> n;cur=n;cnt=n*34;
    vector<vector<int>> par(n+1,vector<int>(17,0)),edge(cnt+1),adj(n+1);
    vector<int> dep(n+1,0);
    for(int i=1;i<n;i++){
        int u,v;cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    function<void(int,int)> dfs = [&](int u,int p){
        par[u][0]=p;dep[u]=dep[p]+1;
        for(int v:adj[u]){
            if(v==p) continue;
            dfs(v,u);
        }
    };
    dfs(1,0);
    for(int i=1;i<=16;i++){
        for(int j=1;j<=n;j++){
            par[j][i]=par[par[j][i-1]][i-1];
            edge[n*i+j].push_back(n*(i-1)+j);
            edge[n*i+j].push_back(n*(i-1)+par[j][i-1]);
            edge[17*n+n*(i-1)+j].push_back(17*n+n*i+j);
            edge[17*n+n*(i-1)+par[j][i-1]].push_back(17*n+n*i+j);
        }
    }
    auto lca = [=](int u,int v){
        if(dep[u]>dep[v]) swap(u,v);
        for(int i=0;i<=16;i++){
            if((dep[v]-dep[u])&(1<<i)) v=par[v][i];
        }
        if(v==u) return u;
        for(int i=16;i>=0;i--){
            if(par[u][i]!=par[v][i]){
                u=par[u][i];
                v=par[v][i];
            }
        }
        return par[u][0];
    };
    int m;cin >> m;
    while(m--){
        int u,v;cin >> u >> v;
        edge[u].push_back(17*n+v);
        edge[17*n+v].push_back(u);
        int a=par[lca(u,v)][0],s=u,t=v;
        for(int i=16;i>=0;i--){
            if((dep[u]-dep[a])&(1<<i)){
                edge[s].push_back(i*n+u);
                edge[17*n+i*n+u].push_back(17*n+t);
                u=par[u][i];
            }
        }
        for(int i=16;i>=0;i--){
            if((dep[v]-dep[a])&(1<<i)){
                edge[s].push_back(i*n+v);
                edge[17*n+i*n+v].push_back(17*n+t);
                v=par[v][i];
            }
        }
    }
    int pos=0;
    vector<int> low(cnt+1,0),num(cnt+1,0),st;
    vector<bool> inst(cnt+1,false);
    bool ok=true;
    function<void(int)> dfs2 = [&](int u){
        num[u]=low[u]=++pos;
        st.push_back(u);inst[u]=true;
        for(int v:edge[u]){
            if(!num[v]){
                dfs2(v);
                low[u]=min(low[u],low[v]);
            }
            else if(inst[v]) low[u]=min(low[u],num[v]);
        }
        if(low[u]==num[u]){
            int ver=0,v=0;
            do{
                v=st.back();st.pop_back();
                inst[v]=false;ver+=(v<=n);
            }
            while(v!=u);
            if(ver>=2) ok=false;
        }
    };
    for(int i=1;i<=cnt;i++){
        if(!num[i]) dfs2(i);
    }
    cout << (ok?"Yes":"No") << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;cin >> test;
    while(test--) solve();
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:51:9: warning: variable 'cur' set but not used [-Wunused-but-set-variable]
   51 |     int cur,cnt,n;cin >> n;cur=n;cnt=n*34;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 204 ms 688 KB Output is correct
5 Correct 488 ms 1432 KB Output is correct
6 Correct 21 ms 1156 KB Output is correct
7 Correct 20 ms 1100 KB Output is correct
8 Correct 24 ms 1164 KB Output is correct
9 Correct 676 ms 20604 KB Output is correct
10 Correct 942 ms 342184 KB Output is correct
11 Correct 89 ms 532 KB Output is correct
12 Correct 506 ms 1704 KB Output is correct
13 Correct 1035 ms 358528 KB Output is correct
14 Correct 1043 ms 373280 KB Output is correct
15 Correct 2148 ms 470376 KB Output is correct
16 Correct 3064 ms 617808 KB Output is correct
17 Correct 995 ms 375060 KB Output is correct
18 Correct 768 ms 369876 KB Output is correct
19 Correct 913 ms 366280 KB Output is correct
20 Correct 941 ms 366276 KB Output is correct
21 Correct 1303 ms 451720 KB Output is correct
22 Correct 799 ms 358172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 21 ms 1124 KB Output is correct
4 Correct 21 ms 1092 KB Output is correct
5 Correct 20 ms 1140 KB Output is correct
6 Correct 20 ms 1092 KB Output is correct
7 Correct 21 ms 1156 KB Output is correct
8 Correct 20 ms 1152 KB Output is correct
9 Correct 19 ms 1124 KB Output is correct
10 Correct 21 ms 1156 KB Output is correct
11 Correct 19 ms 1036 KB Output is correct
12 Correct 10 ms 1080 KB Output is correct
13 Correct 11 ms 1072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 21 ms 1124 KB Output is correct
4 Correct 21 ms 1092 KB Output is correct
5 Correct 20 ms 1140 KB Output is correct
6 Correct 20 ms 1092 KB Output is correct
7 Correct 21 ms 1156 KB Output is correct
8 Correct 20 ms 1152 KB Output is correct
9 Correct 19 ms 1124 KB Output is correct
10 Correct 21 ms 1156 KB Output is correct
11 Correct 19 ms 1036 KB Output is correct
12 Correct 10 ms 1080 KB Output is correct
13 Correct 11 ms 1072 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 1164 KB Output is correct
17 Correct 19 ms 1036 KB Output is correct
18 Correct 19 ms 1084 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 20 ms 1096 KB Output is correct
21 Correct 19 ms 1148 KB Output is correct
22 Correct 18 ms 1164 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 580 KB Output is correct
25 Correct 21 ms 1108 KB Output is correct
26 Correct 5 ms 1036 KB Output is correct
27 Correct 19 ms 1160 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 21 ms 1124 KB Output is correct
4 Correct 21 ms 1092 KB Output is correct
5 Correct 20 ms 1140 KB Output is correct
6 Correct 20 ms 1092 KB Output is correct
7 Correct 21 ms 1156 KB Output is correct
8 Correct 20 ms 1152 KB Output is correct
9 Correct 19 ms 1124 KB Output is correct
10 Correct 21 ms 1156 KB Output is correct
11 Correct 19 ms 1036 KB Output is correct
12 Correct 10 ms 1080 KB Output is correct
13 Correct 11 ms 1072 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 1164 KB Output is correct
17 Correct 19 ms 1036 KB Output is correct
18 Correct 19 ms 1084 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 20 ms 1096 KB Output is correct
21 Correct 19 ms 1148 KB Output is correct
22 Correct 18 ms 1164 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 580 KB Output is correct
25 Correct 21 ms 1108 KB Output is correct
26 Correct 5 ms 1036 KB Output is correct
27 Correct 19 ms 1160 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 21 ms 1164 KB Output is correct
30 Correct 24 ms 1164 KB Output is correct
31 Correct 22 ms 1212 KB Output is correct
32 Correct 24 ms 1156 KB Output is correct
33 Correct 23 ms 1036 KB Output is correct
34 Correct 17 ms 988 KB Output is correct
35 Correct 19 ms 980 KB Output is correct
36 Correct 16 ms 980 KB Output is correct
37 Correct 12 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 21 ms 1124 KB Output is correct
4 Correct 21 ms 1092 KB Output is correct
5 Correct 20 ms 1140 KB Output is correct
6 Correct 20 ms 1092 KB Output is correct
7 Correct 21 ms 1156 KB Output is correct
8 Correct 20 ms 1152 KB Output is correct
9 Correct 19 ms 1124 KB Output is correct
10 Correct 21 ms 1156 KB Output is correct
11 Correct 19 ms 1036 KB Output is correct
12 Correct 10 ms 1080 KB Output is correct
13 Correct 11 ms 1072 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 1164 KB Output is correct
17 Correct 19 ms 1036 KB Output is correct
18 Correct 19 ms 1084 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 20 ms 1096 KB Output is correct
21 Correct 19 ms 1148 KB Output is correct
22 Correct 18 ms 1164 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 580 KB Output is correct
25 Correct 21 ms 1108 KB Output is correct
26 Correct 5 ms 1036 KB Output is correct
27 Correct 19 ms 1160 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 21 ms 1164 KB Output is correct
30 Correct 24 ms 1164 KB Output is correct
31 Correct 22 ms 1212 KB Output is correct
32 Correct 24 ms 1156 KB Output is correct
33 Correct 23 ms 1036 KB Output is correct
34 Correct 17 ms 988 KB Output is correct
35 Correct 19 ms 980 KB Output is correct
36 Correct 16 ms 980 KB Output is correct
37 Correct 12 ms 944 KB Output is correct
38 Correct 675 ms 20508 KB Output is correct
39 Correct 843 ms 342220 KB Output is correct
40 Correct 648 ms 20884 KB Output is correct
41 Correct 599 ms 20500 KB Output is correct
42 Correct 540 ms 20532 KB Output is correct
43 Correct 626 ms 20468 KB Output is correct
44 Correct 82 ms 3724 KB Output is correct
45 Correct 899 ms 346320 KB Output is correct
46 Correct 1115 ms 346328 KB Output is correct
47 Correct 911 ms 347944 KB Output is correct
48 Correct 957 ms 347916 KB Output is correct
49 Correct 730 ms 347936 KB Output is correct
50 Correct 847 ms 347840 KB Output is correct
51 Correct 784 ms 349156 KB Output is correct
52 Correct 792 ms 348992 KB Output is correct
53 Correct 145 ms 24428 KB Output is correct
54 Correct 1020 ms 347680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 97 ms 392 KB Output is correct
6 Correct 10 ms 1048 KB Output is correct
7 Correct 10 ms 1072 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 324 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 17 ms 1052 KB Output is correct
13 Correct 262 ms 1184 KB Output is correct
14 Correct 464 ms 1596 KB Output is correct
15 Correct 348 ms 1460 KB Output is correct
16 Correct 997 ms 347832 KB Output is correct
17 Correct 1298 ms 370544 KB Output is correct
18 Correct 1463 ms 419436 KB Output is correct
19 Correct 932 ms 348780 KB Output is correct
20 Correct 855 ms 348884 KB Output is correct
21 Correct 875 ms 348860 KB Output is correct
22 Correct 1020 ms 360204 KB Output is correct
23 Correct 1078 ms 357568 KB Output is correct
24 Correct 950 ms 353620 KB Output is correct
25 Correct 1012 ms 353584 KB Output is correct
26 Correct 972 ms 353604 KB Output is correct
27 Correct 1350 ms 378136 KB Output is correct
28 Correct 1164 ms 381844 KB Output is correct
29 Correct 1116 ms 369992 KB Output is correct
30 Correct 986 ms 359708 KB Output is correct
31 Correct 1041 ms 365456 KB Output is correct
32 Correct 1136 ms 355516 KB Output is correct
33 Correct 1122 ms 361496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 204 ms 688 KB Output is correct
5 Correct 488 ms 1432 KB Output is correct
6 Correct 21 ms 1156 KB Output is correct
7 Correct 20 ms 1100 KB Output is correct
8 Correct 24 ms 1164 KB Output is correct
9 Correct 676 ms 20604 KB Output is correct
10 Correct 942 ms 342184 KB Output is correct
11 Correct 89 ms 532 KB Output is correct
12 Correct 506 ms 1704 KB Output is correct
13 Correct 1035 ms 358528 KB Output is correct
14 Correct 1043 ms 373280 KB Output is correct
15 Correct 2148 ms 470376 KB Output is correct
16 Correct 3064 ms 617808 KB Output is correct
17 Correct 995 ms 375060 KB Output is correct
18 Correct 768 ms 369876 KB Output is correct
19 Correct 913 ms 366280 KB Output is correct
20 Correct 941 ms 366276 KB Output is correct
21 Correct 1303 ms 451720 KB Output is correct
22 Correct 799 ms 358172 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 21 ms 1124 KB Output is correct
26 Correct 21 ms 1092 KB Output is correct
27 Correct 20 ms 1140 KB Output is correct
28 Correct 20 ms 1092 KB Output is correct
29 Correct 21 ms 1156 KB Output is correct
30 Correct 20 ms 1152 KB Output is correct
31 Correct 19 ms 1124 KB Output is correct
32 Correct 21 ms 1156 KB Output is correct
33 Correct 19 ms 1036 KB Output is correct
34 Correct 10 ms 1080 KB Output is correct
35 Correct 11 ms 1072 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 20 ms 1164 KB Output is correct
39 Correct 19 ms 1036 KB Output is correct
40 Correct 19 ms 1084 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 20 ms 1096 KB Output is correct
43 Correct 19 ms 1148 KB Output is correct
44 Correct 18 ms 1164 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 580 KB Output is correct
47 Correct 21 ms 1108 KB Output is correct
48 Correct 5 ms 1036 KB Output is correct
49 Correct 19 ms 1160 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 21 ms 1164 KB Output is correct
52 Correct 24 ms 1164 KB Output is correct
53 Correct 22 ms 1212 KB Output is correct
54 Correct 24 ms 1156 KB Output is correct
55 Correct 23 ms 1036 KB Output is correct
56 Correct 17 ms 988 KB Output is correct
57 Correct 19 ms 980 KB Output is correct
58 Correct 16 ms 980 KB Output is correct
59 Correct 12 ms 944 KB Output is correct
60 Correct 675 ms 20508 KB Output is correct
61 Correct 843 ms 342220 KB Output is correct
62 Correct 648 ms 20884 KB Output is correct
63 Correct 599 ms 20500 KB Output is correct
64 Correct 540 ms 20532 KB Output is correct
65 Correct 626 ms 20468 KB Output is correct
66 Correct 82 ms 3724 KB Output is correct
67 Correct 899 ms 346320 KB Output is correct
68 Correct 1115 ms 346328 KB Output is correct
69 Correct 911 ms 347944 KB Output is correct
70 Correct 957 ms 347916 KB Output is correct
71 Correct 730 ms 347936 KB Output is correct
72 Correct 847 ms 347840 KB Output is correct
73 Correct 784 ms 349156 KB Output is correct
74 Correct 792 ms 348992 KB Output is correct
75 Correct 145 ms 24428 KB Output is correct
76 Correct 1020 ms 347680 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 97 ms 392 KB Output is correct
82 Correct 10 ms 1048 KB Output is correct
83 Correct 10 ms 1072 KB Output is correct
84 Correct 2 ms 340 KB Output is correct
85 Correct 2 ms 324 KB Output is correct
86 Correct 2 ms 596 KB Output is correct
87 Correct 3 ms 340 KB Output is correct
88 Correct 17 ms 1052 KB Output is correct
89 Correct 262 ms 1184 KB Output is correct
90 Correct 464 ms 1596 KB Output is correct
91 Correct 348 ms 1460 KB Output is correct
92 Correct 997 ms 347832 KB Output is correct
93 Correct 1298 ms 370544 KB Output is correct
94 Correct 1463 ms 419436 KB Output is correct
95 Correct 932 ms 348780 KB Output is correct
96 Correct 855 ms 348884 KB Output is correct
97 Correct 875 ms 348860 KB Output is correct
98 Correct 1020 ms 360204 KB Output is correct
99 Correct 1078 ms 357568 KB Output is correct
100 Correct 950 ms 353620 KB Output is correct
101 Correct 1012 ms 353584 KB Output is correct
102 Correct 972 ms 353604 KB Output is correct
103 Correct 1350 ms 378136 KB Output is correct
104 Correct 1164 ms 381844 KB Output is correct
105 Correct 1116 ms 369992 KB Output is correct
106 Correct 986 ms 359708 KB Output is correct
107 Correct 1041 ms 365456 KB Output is correct
108 Correct 1136 ms 355516 KB Output is correct
109 Correct 1122 ms 361496 KB Output is correct
110 Correct 470 ms 1920 KB Output is correct
111 Correct 357 ms 1348 KB Output is correct
112 Correct 2001 ms 461712 KB Output is correct
113 Correct 1279 ms 353348 KB Output is correct
114 Correct 1511 ms 425912 KB Output is correct
115 Correct 572 ms 345920 KB Output is correct
116 Correct 1236 ms 351264 KB Output is correct
117 Correct 1675 ms 424984 KB Output is correct
118 Correct 981 ms 347776 KB Output is correct
119 Correct 1064 ms 347828 KB Output is correct
120 Correct 93 ms 29744 KB Output is correct
121 Correct 1351 ms 353952 KB Output is correct
122 Correct 1382 ms 354020 KB Output is correct
123 Correct 1403 ms 355484 KB Output is correct
124 Correct 1503 ms 372072 KB Output is correct
125 Correct 1478 ms 356352 KB Output is correct
126 Correct 2872 ms 564152 KB Output is correct
127 Correct 1756 ms 457076 KB Output is correct
128 Correct 1200 ms 449716 KB Output is correct
129 Correct 1186 ms 366952 KB Output is correct
130 Correct 1268 ms 397820 KB Output is correct