Submission #994305

# Submission time Handle Problem Language Result Execution time Memory
994305 2024-06-07T10:32:06 Z vjudge1 Jail (JOI22_jail) C++17
72 / 100
4771 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 120'001, mbit = 18;
int n, m;
int dth[maxn];
int S[maxn], T[maxn];
vector <vector <int> > G;
vector <int> Si, Ti;
vector <int> w;
vector <vector <int> > g;
vector <int> stp;

void dfs_pa(int u = 1){
    for(auto v : G[u]){
        if(v != stp[u]){
            stp[v] = u;
            dth[v] = dth[u] + 1;
            dfs_pa(v);
        }
    }
}


bool dfs_loop(int u){
    if(w[u] == 1) return 1;
    if(w[u] == 2) return 0;
    w[u] = 1;
    for(auto v : g[u]){
        if(dfs_loop(v)) return 1;
    }
    w[u] = 2;
    return 0;
}

bool sol(){
    cin >> n;
    G.assign(n + 1, vector<int>());
    stp.assign(n + 1, 0);
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dth[1] = 0;
    dfs_pa();
    //===============
    cin >> m;
    g.assign(m + 1, vector<int>());
    Si.assign(n + 1, -1);
    Ti.assign(n + 1, -1);
    for(int i = 0; i < m; i++){
        cin >> S[i] >> T[i];
        Si[S[i]] = i;
        Ti[T[i]] = i;
    }
    for(int i = 0; i < m; i++){
        int u = S[i], v = T[i];
        while(u != v){
            if(dth[u] < dth[v]) swap(u, v);
            int s = Si[u], t = Ti[u];
            if(s != -1 && s != i) g[i].push_back(s);
            if(t != -1 && t != i) g[t].push_back(i);
            u = stp[u];
        }
        int s = Si[u], t = Ti[u];
        if(s != -1 && s != i) g[i].push_back(s);
        if(t != -1 && t != i) g[t].push_back(i);
    }
    w.assign(m + 1, 0);
    for(int i = 0; i < m; i++){
        if(dfs_loop(i)) return 0;
    }
    return 1;
}

int main(){
    int Q;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> Q;
    while(Q--){
        cout << (sol() ? "Yes\n" : "No\n");
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 14 ms 496 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 55 ms 3164 KB Output is correct
10 Correct 193 ms 17748 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 33 ms 592 KB Output is correct
13 Correct 110 ms 47812 KB Output is correct
14 Correct 117 ms 61652 KB Output is correct
15 Runtime error 4771 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 516 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 1 ms 528 KB Output is correct
26 Correct 0 ms 472 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 516 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 1 ms 528 KB Output is correct
26 Correct 0 ms 472 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 540 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 516 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 532 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 1 ms 528 KB Output is correct
26 Correct 0 ms 472 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 540 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 54 ms 3984 KB Output is correct
39 Correct 177 ms 18812 KB Output is correct
40 Correct 31 ms 3160 KB Output is correct
41 Correct 18 ms 1804 KB Output is correct
42 Correct 25 ms 3232 KB Output is correct
43 Correct 15 ms 1880 KB Output is correct
44 Correct 4 ms 968 KB Output is correct
45 Correct 30 ms 10052 KB Output is correct
46 Correct 32 ms 10068 KB Output is correct
47 Correct 52 ms 13652 KB Output is correct
48 Correct 83 ms 13856 KB Output is correct
49 Correct 50 ms 10320 KB Output is correct
50 Correct 33 ms 10084 KB Output is correct
51 Correct 23 ms 11356 KB Output is correct
52 Correct 24 ms 11148 KB Output is correct
53 Correct 6 ms 1372 KB Output is correct
54 Correct 34 ms 9892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 10 ms 576 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 12 ms 348 KB Output is correct
16 Correct 37 ms 9732 KB Output is correct
17 Correct 66 ms 17844 KB Output is correct
18 Correct 155 ms 39100 KB Output is correct
19 Correct 39 ms 11088 KB Output is correct
20 Correct 40 ms 11348 KB Output is correct
21 Correct 60 ms 11092 KB Output is correct
22 Correct 61 ms 18640 KB Output is correct
23 Correct 53 ms 19020 KB Output is correct
24 Correct 59 ms 18640 KB Output is correct
25 Correct 54 ms 19016 KB Output is correct
26 Correct 54 ms 17324 KB Output is correct
27 Correct 65 ms 20424 KB Output is correct
28 Correct 63 ms 21008 KB Output is correct
29 Correct 56 ms 19144 KB Output is correct
30 Correct 44 ms 14548 KB Output is correct
31 Correct 47 ms 15016 KB Output is correct
32 Correct 40 ms 14528 KB Output is correct
33 Correct 41 ms 14796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 14 ms 496 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 55 ms 3164 KB Output is correct
10 Correct 193 ms 17748 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 33 ms 592 KB Output is correct
13 Correct 110 ms 47812 KB Output is correct
14 Correct 117 ms 61652 KB Output is correct
15 Runtime error 4771 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -