Submission #955741

# Submission time Handle Problem Language Result Execution time Memory
955741 2024-03-31T11:36:27 Z aymanrs Jail (JOI22_jail) C++14
61 / 100
5000 ms 31688 KB
#include<bits/stdc++.h>
using namespace std;
bool f; int T;
void dfs(int n, vector<int> g[], int p, vector<int>& path){
    path.push_back(n);
    if(n == T){
        f = true;
        return;
    }
    for(int c : g[n]){
        if(f) break;
        if(c == p) continue;
        dfs(c, g, n, path);
    }
    if(!f) path.pop_back();
}
struct node {
    vector<node*> l;
    bool v = false, c = false;
};
bool ans;
void dfs(node* n){
    n->v = n->c = true;
    for(node* c : n->l){
        if(!ans) break;
        if(c->c){
            ans = false;
            break;
        }
        if(!c->v) dfs(c);
    }
    n->c = false;
}
void solve(){
    int n,m;cin >> n;
    vector<int> g[n+1];
    for(int i = 1;i < n;i++){
        int u, v;cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    cin >> m;
    int s[m], t[m];
    int sn[n+1], tn[n+1];
    fill(sn+1, sn+n+1, -1);fill(tn+1, tn+n+1, -1);
    for(int i = 0;i < m;i++){
        cin >> s[i] >> t[i];
        sn[s[i]] = i;
        tn[t[i]] = i;
    }
    node mg[m];
    for(int i = 0;i < m;i++){
        vector<int> path;
        f = false;T = t[i];
        dfs(s[i], g, -1, path);
        for(int _ : path){
            if(sn[_] != -1 && sn[_] != i) mg[i].l.push_back(&mg[sn[_]]);
            if(tn[_] != -1 && tn[_] != i) mg[tn[_]].l.push_back(&mg[i]);
        }
    }
    ans = true;
    for(int i = 0;i < m && ans;i++){
        if(!mg[i].v) dfs(&mg[i]);
    }
    if(ans)cout << "Yes\n";
    else cout << "No\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;cin >> t;
    while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 604 KB Output is correct
5 Correct 19 ms 960 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 302 ms 4904 KB Output is correct
10 Correct 1150 ms 20528 KB Output is correct
11 Correct 6 ms 600 KB Output is correct
12 Correct 56 ms 1360 KB Output is correct
13 Execution timed out 5020 ms 31688 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 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 348 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 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 348 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 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 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 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 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 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 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 348 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 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 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 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 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 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 5 ms 604 KB Output is correct
30 Correct 3 ms 484 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 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 348 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 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 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 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 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 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 5 ms 604 KB Output is correct
30 Correct 3 ms 484 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 282 ms 3784 KB Output is correct
39 Correct 1094 ms 20156 KB Output is correct
40 Correct 409 ms 2764 KB Output is correct
41 Correct 353 ms 1620 KB Output is correct
42 Correct 217 ms 2688 KB Output is correct
43 Correct 44 ms 1628 KB Output is correct
44 Correct 44 ms 852 KB Output is correct
45 Correct 1027 ms 9056 KB Output is correct
46 Correct 992 ms 9308 KB Output is correct
47 Correct 596 ms 13448 KB Output is correct
48 Correct 594 ms 13576 KB Output is correct
49 Correct 708 ms 9344 KB Output is correct
50 Correct 669 ms 9228 KB Output is correct
51 Correct 202 ms 10460 KB Output is correct
52 Correct 215 ms 10408 KB Output is correct
53 Correct 36 ms 1116 KB Output is correct
54 Correct 750 ms 9088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
5 Correct 6 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 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 29 ms 460 KB Output is correct
14 Correct 39 ms 348 KB Output is correct
15 Correct 37 ms 348 KB Output is correct
16 Execution timed out 5025 ms 9344 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 604 KB Output is correct
5 Correct 19 ms 960 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 302 ms 4904 KB Output is correct
10 Correct 1150 ms 20528 KB Output is correct
11 Correct 6 ms 600 KB Output is correct
12 Correct 56 ms 1360 KB Output is correct
13 Execution timed out 5020 ms 31688 KB Time limit exceeded
14 Halted 0 ms 0 KB -