Submission #955739

# Submission time Handle Problem Language Result Execution time Memory
955739 2024-03-31T11:33:13 Z aymanrs Jail (JOI22_jail) C++14
49 / 100
5000 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;
bool f; int T;
void dfs(int n, vector<int> g[], int p, set<int>& path){
    path.insert(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.erase(n);
}
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;
    set<int> path[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];f = false;T = t[i];
        sn[s[i]] = i;
        tn[t[i]] = i;
        dfs(s[i], g, -1, path[i]);
    }
    node mg[m];
    for(int i = 0;i < m;i++){
        for(int _ : path[i]){
            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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 824 KB Output is correct
5 Correct 27 ms 1116 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 15 ms 1244 KB Output is correct
9 Correct 2459 ms 134344 KB Output is correct
10 Runtime error 3650 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# 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 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 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 344 KB Output is correct
13 Correct 1 ms 348 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 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 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 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 428 KB Output is correct
28 Correct 1 ms 344 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 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 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 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 428 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 16 ms 1624 KB Output is correct
30 Correct 11 ms 348 KB Output is correct
31 Correct 12 ms 604 KB Output is correct
32 Correct 12 ms 600 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 14 ms 576 KB Output is correct
35 Correct 12 ms 860 KB Output is correct
36 Correct 11 ms 348 KB Output is correct
37 Correct 10 ms 472 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 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 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 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 428 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 16 ms 1624 KB Output is correct
30 Correct 11 ms 348 KB Output is correct
31 Correct 12 ms 604 KB Output is correct
32 Correct 12 ms 600 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 14 ms 576 KB Output is correct
35 Correct 12 ms 860 KB Output is correct
36 Correct 11 ms 348 KB Output is correct
37 Correct 10 ms 472 KB Output is correct
38 Correct 2449 ms 133956 KB Output is correct
39 Runtime error 3198 ms 1048576 KB Execution killed with signal 9
40 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 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 9 ms 604 KB Output is correct
6 Correct 1 ms 344 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 1 ms 452 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 108 ms 1044 KB Output is correct
14 Correct 144 ms 1184 KB Output is correct
15 Correct 132 ms 848 KB Output is correct
16 Execution timed out 5020 ms 11080 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 824 KB Output is correct
5 Correct 27 ms 1116 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 15 ms 1244 KB Output is correct
9 Correct 2459 ms 134344 KB Output is correct
10 Runtime error 3650 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -