Submission #636198

# Submission time Handle Problem Language Result Execution time Memory
636198 2022-08-28T13:41:45 Z Yazan_Alattar Jail (JOI22_jail) C++14
49 / 100
5000 ms 17480 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

vector <int> adj[M], to[M];
int n, m, s[M], t[M], dep[M], p[M], in[M], st[M], out[M], timer;

bool check(int i, int j){
    int x = s[i], y = t[i];

    while(x != y){
        if(x == s[j] || y == s[j]) return 0;

        if(dep[x] > dep[y]) x = p[x];
        else y = p[y];
    }
    if(x == s[j]) return 0;

    x = s[j], y = t[j];
    while(x != y){
        if(x == t[i] || y == t[i]) return 0;

        if(dep[x] > dep[y]) x = p[x];
        else y = p[y];
    }

    return x != t[i];
}

void dfs(int node, int par){
    st[node] = ++timer;
    for(auto i : adj[node]) if(i != par){
        dep[i] = dep[node] + 1;
        p[i] = node;
        dfs(i, node);
    }
    out[node] = ++timer;
    return;
}

bool con(int i, int j){
    return st[i] <= st[j] && out[i] >= out[j];
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q;
    cin >> q;
    while(q--){
        cin >> n;
        for(int i = 1; i < n; ++i){
            int x, y;
            cin >> x >> y;
            adj[x].pb(y);
            adj[y].pb(x);
        }

        dep[1] = 1;
        dfs(1, 0);

        cin >> m;
        for(int i = 1; i <= m; ++i) cin >> s[i] >> t[i];

        for(int i = 1; i <= m; ++i){
            for(int j = 1; j <= m; ++j){
                if(i != j && !check(i, j)) to[j].pb(i), ++in[i];
            }
        }

        queue <int> q;
        for(int i = 1; i <= m; ++i) if(!in[i]) q.push(i);

        int cnt = 0;
        while(!q.empty()){
            int node = q.front();
            q.pop();
            ++cnt;

            for(auto i : to[node]){
                --in[i];
                if(!in[i]) q.push(i);
            }
        }

        cout << (cnt != m ? "No\n" : "Yes\n");

        for(int i = 1; i <= n; ++i){
            adj[i].clear();
            to[i].clear();
            in[i] = 0;
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 16 ms 9684 KB Output is correct
5 Correct 22 ms 9760 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 31 ms 9812 KB Output is correct
9 Execution timed out 5099 ms 11520 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9752 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9664 KB Output is correct
5 Correct 7 ms 9736 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9796 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9736 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9752 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9664 KB Output is correct
5 Correct 7 ms 9736 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9796 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9736 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9736 KB Output is correct
14 Correct 7 ms 9724 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9740 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9736 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 5 ms 9720 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 6 ms 9724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9752 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9664 KB Output is correct
5 Correct 7 ms 9736 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9796 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9736 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9736 KB Output is correct
14 Correct 7 ms 9724 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9740 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9736 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 5 ms 9720 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 6 ms 9724 KB Output is correct
29 Correct 33 ms 9836 KB Output is correct
30 Correct 11 ms 9812 KB Output is correct
31 Correct 17 ms 9848 KB Output is correct
32 Correct 13 ms 9820 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 12 ms 9812 KB Output is correct
35 Correct 38 ms 9848 KB Output is correct
36 Correct 8 ms 9812 KB Output is correct
37 Correct 11 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9752 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9664 KB Output is correct
5 Correct 7 ms 9736 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9796 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9736 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9736 KB Output is correct
14 Correct 7 ms 9724 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9740 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9736 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 5 ms 9720 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 6 ms 9724 KB Output is correct
29 Correct 33 ms 9836 KB Output is correct
30 Correct 11 ms 9812 KB Output is correct
31 Correct 17 ms 9848 KB Output is correct
32 Correct 13 ms 9820 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 12 ms 9812 KB Output is correct
35 Correct 38 ms 9848 KB Output is correct
36 Correct 8 ms 9812 KB Output is correct
37 Correct 11 ms 9684 KB Output is correct
38 Execution timed out 5068 ms 12648 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9752 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 10 ms 9684 KB Output is correct
6 Correct 6 ms 9764 KB Output is correct
7 Correct 6 ms 9732 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9736 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 9 ms 9732 KB Output is correct
13 Correct 94 ms 10324 KB Output is correct
14 Correct 67 ms 10632 KB Output is correct
15 Correct 71 ms 10384 KB Output is correct
16 Execution timed out 5042 ms 17480 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 16 ms 9684 KB Output is correct
5 Correct 22 ms 9760 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 31 ms 9812 KB Output is correct
9 Execution timed out 5099 ms 11520 KB Time limit exceeded
10 Halted 0 ms 0 KB -