Submission #550654

# Submission time Handle Problem Language Result Execution time Memory
550654 2022-04-18T18:58:42 Z doowey Jail (JOI22_jail) C++14
72 / 100
5000 ms 870324 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 123456;
vector<int> T[N];

int par[N];
int S[N], E[N];
int ss[N], ee[N];
int tin[N];
int tout[N];
int ti;

void dfs(int u, int pp){
    ti ++ ;
    tin[u] = ti;
    par[u] = pp;
    for(auto x : T[u]){
        if(x == pp) continue;
        dfs(x, u);
    }
    tout[u] = ti;
}

bool is_par(int u, int v){
    if(tin[u] <= tin[v] && tout[u] >= tout[v]) return true;
    return false;
}

vector<int> G[N];

bool cycle;
int vis[N];

void dfs1(int u){
    if(vis[u] == 1){
        cycle = true;
        return;
    }
    if(vis[u] == 2){
        return;
    }
    vis[u] = 1;
    for(auto x : G[u]){
        dfs1(x);
    }
    vis[u] = 2;
}

void solve(){
    int n, m;
    cin >> n;
    for(int i = 1; i <= n; i ++ ){
        T[i].clear();
        G[i].clear();
        ss[i] = ee[i] = -1;
    }
    int u, v;
    for(int i = 1; i < n; i ++ ){
        cin >> u >> v;
        T[u].push_back(v);
        T[v].push_back(u);
    }
    ti = 0;
    dfs(1, -1);
    cin >> m;
    for(int i = 1; i <= m ; i ++ ){
        cin >> S[i] >> E[i];
        ss[S[i]] = i;
        ee[E[i]] = i;
    }
    int uu;
    for(int iq = 1; iq <= m ; iq ++ ){
        uu = S[iq];
        while(!is_par(uu, E[iq])){
            if(ss[uu] != -1 && ss[uu] != iq){
                G[ss[uu]].push_back(iq);
            }
            if(ee[uu] != -1 && ee[uu] != iq){
                G[iq].push_back(ee[uu]);
            }
            uu = par[uu];
        }
        if(ss[uu] != -1 && ss[uu] != iq){
            G[ss[uu]].push_back(iq);
        }
        if(ee[uu] != -1 && ee[uu] != iq){
            G[iq].push_back(ee[uu]);
        }
        uu = E[iq];
        while(!is_par(uu, S[iq])){
            if(ss[uu] != -1 && ss[uu] != iq){
                G[ss[uu]].push_back(iq);
            }
            if(ee[uu] != -1 && ee[uu] != iq){
                G[iq].push_back(ee[uu]);
            }
            uu = par[uu];
        }
        vis[iq] = 0;
    }
    cycle = false;
    for(int i = 1; i <= m ; i ++ ){
        if(vis[i] == 0){
            dfs1(i);
        }
    }
    if(!cycle){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

int main(){
    fastIO;
    //freopen("in.txt","r",stdin);
    int tc;
    cin >> tc;
    for(int iq = 1; iq <= tc; iq ++ ){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 11 ms 6228 KB Output is correct
5 Correct 22 ms 6204 KB Output is correct
6 Correct 5 ms 6100 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 5 ms 6228 KB Output is correct
9 Correct 75 ms 9668 KB Output is correct
10 Correct 213 ms 19880 KB Output is correct
11 Correct 8 ms 6268 KB Output is correct
12 Correct 37 ms 7108 KB Output is correct
13 Correct 119 ms 49568 KB Output is correct
14 Correct 157 ms 63804 KB Output is correct
15 Execution timed out 5083 ms 870324 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 5 ms 6216 KB Output is correct
4 Correct 4 ms 6136 KB Output is correct
5 Correct 4 ms 6148 KB Output is correct
6 Correct 4 ms 6212 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 4 ms 6100 KB Output is correct
11 Correct 5 ms 6100 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 4 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 5 ms 6216 KB Output is correct
4 Correct 4 ms 6136 KB Output is correct
5 Correct 4 ms 6148 KB Output is correct
6 Correct 4 ms 6212 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 4 ms 6100 KB Output is correct
11 Correct 5 ms 6100 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 4 ms 6228 KB Output is correct
14 Correct 4 ms 6096 KB Output is correct
15 Correct 4 ms 6128 KB Output is correct
16 Correct 5 ms 6144 KB Output is correct
17 Correct 4 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6100 KB Output is correct
20 Correct 4 ms 6140 KB Output is correct
21 Correct 5 ms 6140 KB Output is correct
22 Correct 4 ms 6140 KB Output is correct
23 Correct 3 ms 6100 KB Output is correct
24 Correct 3 ms 6100 KB Output is correct
25 Correct 4 ms 6100 KB Output is correct
26 Correct 4 ms 6136 KB Output is correct
27 Correct 5 ms 6100 KB Output is correct
28 Correct 4 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 5 ms 6216 KB Output is correct
4 Correct 4 ms 6136 KB Output is correct
5 Correct 4 ms 6148 KB Output is correct
6 Correct 4 ms 6212 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 4 ms 6100 KB Output is correct
11 Correct 5 ms 6100 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 4 ms 6228 KB Output is correct
14 Correct 4 ms 6096 KB Output is correct
15 Correct 4 ms 6128 KB Output is correct
16 Correct 5 ms 6144 KB Output is correct
17 Correct 4 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6100 KB Output is correct
20 Correct 4 ms 6140 KB Output is correct
21 Correct 5 ms 6140 KB Output is correct
22 Correct 4 ms 6140 KB Output is correct
23 Correct 3 ms 6100 KB Output is correct
24 Correct 3 ms 6100 KB Output is correct
25 Correct 4 ms 6100 KB Output is correct
26 Correct 4 ms 6136 KB Output is correct
27 Correct 5 ms 6100 KB Output is correct
28 Correct 4 ms 6100 KB Output is correct
29 Correct 6 ms 6356 KB Output is correct
30 Correct 6 ms 6144 KB Output is correct
31 Correct 5 ms 6240 KB Output is correct
32 Correct 4 ms 6100 KB Output is correct
33 Correct 5 ms 6100 KB Output is correct
34 Correct 4 ms 6140 KB Output is correct
35 Correct 5 ms 6276 KB Output is correct
36 Correct 5 ms 6168 KB Output is correct
37 Correct 4 ms 6144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 5 ms 6216 KB Output is correct
4 Correct 4 ms 6136 KB Output is correct
5 Correct 4 ms 6148 KB Output is correct
6 Correct 4 ms 6212 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 4 ms 6100 KB Output is correct
11 Correct 5 ms 6100 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 4 ms 6228 KB Output is correct
14 Correct 4 ms 6096 KB Output is correct
15 Correct 4 ms 6128 KB Output is correct
16 Correct 5 ms 6144 KB Output is correct
17 Correct 4 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6100 KB Output is correct
20 Correct 4 ms 6140 KB Output is correct
21 Correct 5 ms 6140 KB Output is correct
22 Correct 4 ms 6140 KB Output is correct
23 Correct 3 ms 6100 KB Output is correct
24 Correct 3 ms 6100 KB Output is correct
25 Correct 4 ms 6100 KB Output is correct
26 Correct 4 ms 6136 KB Output is correct
27 Correct 5 ms 6100 KB Output is correct
28 Correct 4 ms 6100 KB Output is correct
29 Correct 6 ms 6356 KB Output is correct
30 Correct 6 ms 6144 KB Output is correct
31 Correct 5 ms 6240 KB Output is correct
32 Correct 4 ms 6100 KB Output is correct
33 Correct 5 ms 6100 KB Output is correct
34 Correct 4 ms 6140 KB Output is correct
35 Correct 5 ms 6276 KB Output is correct
36 Correct 5 ms 6168 KB Output is correct
37 Correct 4 ms 6144 KB Output is correct
38 Correct 93 ms 9264 KB Output is correct
39 Correct 214 ms 20268 KB Output is correct
40 Correct 48 ms 8832 KB Output is correct
41 Correct 35 ms 7424 KB Output is correct
42 Correct 47 ms 8824 KB Output is correct
43 Correct 24 ms 7584 KB Output is correct
44 Correct 9 ms 6484 KB Output is correct
45 Correct 46 ms 13644 KB Output is correct
46 Correct 62 ms 13644 KB Output is correct
47 Correct 69 ms 16504 KB Output is correct
48 Correct 63 ms 16332 KB Output is correct
49 Correct 47 ms 13816 KB Output is correct
50 Correct 58 ms 13776 KB Output is correct
51 Correct 51 ms 13548 KB Output is correct
52 Correct 39 ms 14392 KB Output is correct
53 Correct 11 ms 6612 KB Output is correct
54 Correct 55 ms 13584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 11 ms 6228 KB Output is correct
6 Correct 4 ms 6100 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6128 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 4 ms 6100 KB Output is correct
11 Correct 3 ms 6060 KB Output is correct
12 Correct 4 ms 6144 KB Output is correct
13 Correct 18 ms 6612 KB Output is correct
14 Correct 24 ms 6868 KB Output is correct
15 Correct 21 ms 6744 KB Output is correct
16 Correct 79 ms 13908 KB Output is correct
17 Correct 146 ms 19944 KB Output is correct
18 Correct 317 ms 44972 KB Output is correct
19 Correct 61 ms 13648 KB Output is correct
20 Correct 59 ms 12876 KB Output is correct
21 Correct 54 ms 12956 KB Output is correct
22 Correct 92 ms 20856 KB Output is correct
23 Correct 94 ms 20932 KB Output is correct
24 Correct 90 ms 18868 KB Output is correct
25 Correct 73 ms 19124 KB Output is correct
26 Correct 84 ms 20732 KB Output is correct
27 Correct 119 ms 20008 KB Output is correct
28 Correct 126 ms 24896 KB Output is correct
29 Correct 130 ms 22928 KB Output is correct
30 Correct 77 ms 19408 KB Output is correct
31 Correct 81 ms 19248 KB Output is correct
32 Correct 81 ms 18632 KB Output is correct
33 Correct 74 ms 19048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 11 ms 6228 KB Output is correct
5 Correct 22 ms 6204 KB Output is correct
6 Correct 5 ms 6100 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 5 ms 6228 KB Output is correct
9 Correct 75 ms 9668 KB Output is correct
10 Correct 213 ms 19880 KB Output is correct
11 Correct 8 ms 6268 KB Output is correct
12 Correct 37 ms 7108 KB Output is correct
13 Correct 119 ms 49568 KB Output is correct
14 Correct 157 ms 63804 KB Output is correct
15 Execution timed out 5083 ms 870324 KB Time limit exceeded
16 Halted 0 ms 0 KB -