Submission #581618

# Submission time Handle Problem Language Result Execution time Memory
581618 2022-06-22T21:39:57 Z Lobo Jail (JOI22_jail) C++17
72 / 100
4128 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e5+10;

int n, m, pp[maxn][25], pai[maxn], gr[maxn], h[maxn], s[maxn], t[maxn], st[maxn], ed[maxn];
vector<int> g[maxn], gts[maxn];

void dfslca(int u, int ant) {
    pai[u] = ant;
    pp[u][0] = ant;
    for(int i = 1; i <= 20; i++) {
        pp[u][i] = pp[pp[u][i-1]][i-1];
    }
    for(auto v : g[u]) if(v != ant) {
        h[v] = h[u]+1;
        dfslca(v,u);
    }
}

int lca(int u, int v) {
    if(h[u] < h[v]) swap(u,v);

    for(int i = 20; i >= 0; i--) {
        if(h[pp[u][i]] >= h[v]) {
            u = pp[u][i];
        }
    }
    if(u == v) return u;

    for(int i = 20; i >= 0; i--) {
        if(pp[u][i] != pp[v][i]) {
            u = pp[u][i];
            v = pp[v][i];
        }
    }
    return pp[u][0];
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        gr[i] = 0;
        g[i].clear();
        gts[i].clear();
        st[i] = 0;
        ed[i] = 0;
    }
    for(int i = 0; i < n-1; i++) {
        int u,v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfslca(1,1);
    cin >> m;
    for(int i = 1; i <= m; i++) {
        cin >> s[i] >> t[i];
        st[s[i]] = i;
        ed[t[i]] = i;
    }
    for(int i = 1; i <= m; i++) {
        int lc = lca(s[i],t[i]);
        // cout << s[i] << " "<< t[i] << " " << lc << endl;
        int v;
        v = s[i];
        while(true) {
            if(st[v] != 0 && v != s[i]) {
                gts[st[v]].pb(i);
                gr[i]++;
            }
            if(ed[v] != 0 && v != t[i]) {
                gts[i].pb(ed[v]);
                gr[ed[v]]++;
            }
            if(v == lc) break;
            v = pai[v];
        }
        v = t[i];
        while(true) {
            if(st[v] != 0 && v != s[i]) {
                gts[st[v]].pb(i);
                gr[i]++;
            }
            if(ed[v] != 0 && v != t[i]) {
                gts[i].pb(ed[v]);
                gr[ed[v]]++;
            }
            if(v == lc) break;
            v = pai[v];
        }
    }

    queue<int> q;
    for(int i = 1; i <= m; i++) {
        if(gr[i] == 0) q.push(i);
    }

    while(q.size()) {
        int u = q.front();
        q.pop();
        for(auto v : gts[u]) {
            if(--gr[v] == 0) q.push(v);
        }
    }

    string ans = "Yes";
    for(int i = 1; i <= m; i++) {
        if(gr[i] != 0) ans = "No";
    }
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    cin >> tt;
    while(tt--) {
        solve();
    }

}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 5 ms 9724 KB Output is correct
4 Correct 17 ms 10052 KB Output is correct
5 Correct 30 ms 10448 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 9 ms 10148 KB Output is correct
9 Correct 86 ms 16736 KB Output is correct
10 Correct 264 ms 51384 KB Output is correct
11 Correct 13 ms 9812 KB Output is correct
12 Correct 51 ms 10888 KB Output is correct
13 Correct 199 ms 108760 KB Output is correct
14 Correct 221 ms 136428 KB Output is correct
15 Runtime error 4128 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 7 ms 9868 KB Output is correct
5 Correct 7 ms 9812 KB Output is correct
6 Correct 8 ms 9888 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9892 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 7 ms 9868 KB Output is correct
5 Correct 7 ms 9812 KB Output is correct
6 Correct 8 ms 9888 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9892 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9868 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9728 KB Output is correct
16 Correct 7 ms 9812 KB Output is correct
17 Correct 7 ms 9864 KB Output is correct
18 Correct 7 ms 9892 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9940 KB Output is correct
21 Correct 7 ms 9872 KB Output is correct
22 Correct 7 ms 9812 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 6 ms 9728 KB Output is correct
25 Correct 7 ms 9868 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 7 ms 9856 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 7 ms 9868 KB Output is correct
5 Correct 7 ms 9812 KB Output is correct
6 Correct 8 ms 9888 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9892 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9868 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9728 KB Output is correct
16 Correct 7 ms 9812 KB Output is correct
17 Correct 7 ms 9864 KB Output is correct
18 Correct 7 ms 9892 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9940 KB Output is correct
21 Correct 7 ms 9872 KB Output is correct
22 Correct 7 ms 9812 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 6 ms 9728 KB Output is correct
25 Correct 7 ms 9868 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 7 ms 9856 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 8 ms 10068 KB Output is correct
30 Correct 7 ms 9812 KB Output is correct
31 Correct 8 ms 9940 KB Output is correct
32 Correct 10 ms 9812 KB Output is correct
33 Correct 8 ms 9868 KB Output is correct
34 Correct 8 ms 9812 KB Output is correct
35 Correct 11 ms 9960 KB Output is correct
36 Correct 10 ms 9960 KB Output is correct
37 Correct 8 ms 9868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 7 ms 9868 KB Output is correct
5 Correct 7 ms 9812 KB Output is correct
6 Correct 8 ms 9888 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9892 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9868 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9728 KB Output is correct
16 Correct 7 ms 9812 KB Output is correct
17 Correct 7 ms 9864 KB Output is correct
18 Correct 7 ms 9892 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 7 ms 9940 KB Output is correct
21 Correct 7 ms 9872 KB Output is correct
22 Correct 7 ms 9812 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 6 ms 9728 KB Output is correct
25 Correct 7 ms 9868 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 7 ms 9856 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 8 ms 10068 KB Output is correct
30 Correct 7 ms 9812 KB Output is correct
31 Correct 8 ms 9940 KB Output is correct
32 Correct 10 ms 9812 KB Output is correct
33 Correct 8 ms 9868 KB Output is correct
34 Correct 8 ms 9812 KB Output is correct
35 Correct 11 ms 9960 KB Output is correct
36 Correct 10 ms 9960 KB Output is correct
37 Correct 8 ms 9868 KB Output is correct
38 Correct 96 ms 16588 KB Output is correct
39 Correct 207 ms 51244 KB Output is correct
40 Correct 74 ms 14936 KB Output is correct
41 Correct 52 ms 12632 KB Output is correct
42 Correct 61 ms 15012 KB Output is correct
43 Correct 40 ms 12768 KB Output is correct
44 Correct 15 ms 10508 KB Output is correct
45 Correct 107 ms 43692 KB Output is correct
46 Correct 94 ms 43648 KB Output is correct
47 Correct 99 ms 46412 KB Output is correct
48 Correct 123 ms 46332 KB Output is correct
49 Correct 91 ms 43748 KB Output is correct
50 Correct 76 ms 43696 KB Output is correct
51 Correct 74 ms 44312 KB Output is correct
52 Correct 69 ms 44592 KB Output is correct
53 Correct 18 ms 12296 KB Output is correct
54 Correct 112 ms 44392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9728 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 12 ms 9924 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9692 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 8 ms 9812 KB Output is correct
13 Correct 38 ms 10500 KB Output is correct
14 Correct 46 ms 10680 KB Output is correct
15 Correct 39 ms 10448 KB Output is correct
16 Correct 101 ms 44532 KB Output is correct
17 Correct 211 ms 54884 KB Output is correct
18 Correct 475 ms 94672 KB Output is correct
19 Correct 121 ms 44612 KB Output is correct
20 Correct 110 ms 44364 KB Output is correct
21 Correct 123 ms 44704 KB Output is correct
22 Correct 201 ms 56428 KB Output is correct
23 Correct 168 ms 57304 KB Output is correct
24 Correct 169 ms 55620 KB Output is correct
25 Correct 178 ms 57008 KB Output is correct
26 Correct 160 ms 56856 KB Output is correct
27 Correct 243 ms 49792 KB Output is correct
28 Correct 195 ms 50932 KB Output is correct
29 Correct 197 ms 51084 KB Output is correct
30 Correct 181 ms 47020 KB Output is correct
31 Correct 159 ms 47012 KB Output is correct
32 Correct 156 ms 47156 KB Output is correct
33 Correct 172 ms 47172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 5 ms 9724 KB Output is correct
4 Correct 17 ms 10052 KB Output is correct
5 Correct 30 ms 10448 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 9 ms 10148 KB Output is correct
9 Correct 86 ms 16736 KB Output is correct
10 Correct 264 ms 51384 KB Output is correct
11 Correct 13 ms 9812 KB Output is correct
12 Correct 51 ms 10888 KB Output is correct
13 Correct 199 ms 108760 KB Output is correct
14 Correct 221 ms 136428 KB Output is correct
15 Runtime error 4128 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -