Submission #546329

# Submission time Handle Problem Language Result Execution time Memory
546329 2022-04-07T09:45:03 Z Jarif_Rahman Jail (JOI22_jail) C++17
72 / 100
3531 ms 1048576 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
 
int n, m;
vector<vector<int>> v;
vector<int> s, t;
vector<vector<int>> sth;
vector<int> state;
vector<int> p;
vector<int> d;
bool cycle;
 
void dfs1(int nd, int ss, int dis){
    for(int x: v[nd]) if(x != ss) dfs1(x, nd, dis+1);
    p[nd] = ss;
    d[nd] = dis;
}
 
void dfs2(int nd){
    if(state[nd] == 1){
        cycle = 1;
        return;
    }
    if(state[nd] == 2) return;
    state[nd] = 1;
    for(int x: sth[nd]) dfs2(x);
    state[nd] = 2;
}
 
void solve(){
    cin >> n;
    v.assign(n, {});
    p.assign(n, 0);
    d.assign(n, 0);
    sth.assign(2*n, {});
    state.assign(2*n, 0);

    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b; a--, b--;
        v[a].pb(b);
        v[b].pb(a);
    }
 
    dfs1(0, -1, 0);
 
    cin >> m;
    s.assign(m, 0);
    t.assign(m, 0);
    for(int i = 0; i < m; i++) cin >> s[i] >> t[i], s[i]--, t[i]--;
    for(int i = 0; i < m; i++){
        sth[s[i]].pb(t[i]+n);
    }
  
    auto get_path = [&](int a, int b){
        vector<int> rt;
        if(d[a] > d[b]) swap(a, b);
        while(d[a] != d[b]) rt.pb(b), b = p[b];
        while(a != b) rt.pb(a), rt.pb(b), a = p[a], b = p[b];
        rt.pb(a);
        return rt;
    };
 
    for(int i = 0; i < m; i++){
        for(int x: get_path(s[i], t[i])){
            if(x != s[i]) sth[t[i]+n].pb(x);
            if(x != t[i]) sth[x+n].pb(s[i]);
        }
    }
 
    cycle = 0;
 
    for(int i = 0; i < n; i++) if(state[i] == 0) dfs2(i);
 
    cout << (cycle?"No\n":"Yes\n");
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T; cin >> T; while(T--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 10 ms 340 KB Output is correct
5 Correct 20 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 370 ms 50228 KB Output is correct
10 Correct 2178 ms 502752 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
12 Correct 52 ms 396 KB Output is correct
13 Correct 263 ms 98772 KB Output is correct
14 Correct 381 ms 130716 KB Output is correct
15 Runtime error 3531 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 352 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 352 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 352 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 386 ms 50332 KB Output is correct
39 Correct 2287 ms 502896 KB Output is correct
40 Correct 151 ms 24896 KB Output is correct
41 Correct 34 ms 1796 KB Output is correct
42 Correct 119 ms 22124 KB Output is correct
43 Correct 25 ms 1308 KB Output is correct
44 Correct 11 ms 576 KB Output is correct
45 Correct 65 ms 15448 KB Output is correct
46 Correct 57 ms 15460 KB Output is correct
47 Correct 340 ms 107968 KB Output is correct
48 Correct 367 ms 111156 KB Output is correct
49 Correct 75 ms 20044 KB Output is correct
50 Correct 73 ms 20212 KB Output is correct
51 Correct 39 ms 16000 KB Output is correct
52 Correct 38 ms 16012 KB Output is correct
53 Correct 11 ms 1492 KB Output is correct
54 Correct 73 ms 14636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 26 ms 340 KB Output is correct
14 Correct 41 ms 348 KB Output is correct
15 Correct 31 ms 348 KB Output is correct
16 Correct 78 ms 17536 KB Output is correct
17 Correct 185 ms 30412 KB Output is correct
18 Correct 392 ms 49740 KB Output is correct
19 Correct 92 ms 20424 KB Output is correct
20 Correct 103 ms 20652 KB Output is correct
21 Correct 97 ms 20648 KB Output is correct
22 Correct 217 ms 30404 KB Output is correct
23 Correct 135 ms 30356 KB Output is correct
24 Correct 160 ms 30260 KB Output is correct
25 Correct 179 ms 30792 KB Output is correct
26 Correct 173 ms 30524 KB Output is correct
27 Correct 155 ms 30792 KB Output is correct
28 Correct 192 ms 31244 KB Output is correct
29 Correct 163 ms 27272 KB Output is correct
30 Correct 113 ms 23752 KB Output is correct
31 Correct 127 ms 24720 KB Output is correct
32 Correct 153 ms 22896 KB Output is correct
33 Correct 108 ms 24724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 10 ms 340 KB Output is correct
5 Correct 20 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 370 ms 50228 KB Output is correct
10 Correct 2178 ms 502752 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
12 Correct 52 ms 396 KB Output is correct
13 Correct 263 ms 98772 KB Output is correct
14 Correct 381 ms 130716 KB Output is correct
15 Runtime error 3531 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -