Submission #1039204

# Submission time Handle Problem Language Result Execution time Memory
1039204 2024-07-30T14:29:57 Z Andrey Jail (JOI22_jail) C++14
61 / 100
5000 ms 32544 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> haha[200001];
vector<int> wow(200001);
vector<int> wut(200001);
vector<int> topo[200001];

bool dfs(int a, int t, int x, int p) {
    if(a == x) {
        if(wow[a] != -1 && wow[a] != p) {
            topo[wow[a]].push_back(p);
        }
        if(wut[a] != -1 && wut[a] != p) {
            topo[p].push_back(wut[a]);
        }
        return true;
    }
    for(int v: haha[a]) {
        if(v != t) {
            if(dfs(v,a,x,p)) {
                if(wow[a] != -1 && wow[a] != p) {
                    topo[wow[a]].push_back(p);
                }
                if(wut[a] != -1 && wut[a] != p) {
                    topo[p].push_back(wut[a]);
                }
                return true;
            }
        }
    }
    return false;
}

void solve() {
    int n,m,a,b;
    cin >> n;
    topo[0].clear();
    vector<pair<int,int>> idk(0);
    for(int i = 1; i <= n; i++) {
        haha[i].clear();
        topo[i].clear();
        wow[i] = -1;
        wut[i] = -1;
    }
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    cin >> m;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        wow[a] = i;
        wut[b] = i;
        idk.push_back({a,b});
    }
    for(int i = 0; i < m; i++) {
        dfs(idk[i].first,-1,idk[i].second,i);
    }
    vector<int> br(m);
    for(int i = 0; i < m; i++) {
        for(int v: topo[i]) {
            br[v]++;
        }
    }
    vector<int> ans(0);
    for(int i = 0; i < m; i++) {
        if(br[i] == 0) {
            ans.push_back(i);
        }
    }
    for(int i = 0; i < ans.size(); i++) {
        for(int v: topo[ans[i]]) {
            br[v]--;
            if(br[v] == 0) {
                ans.push_back(v);
            }
        }
    }
    if(ans.size() == m) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
jail.cpp:81:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |     if(ans.size() == m) {
      |        ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 9 ms 11608 KB Output is correct
5 Correct 15 ms 12124 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11236 KB Output is correct
8 Correct 6 ms 11356 KB Output is correct
9 Correct 198 ms 15248 KB Output is correct
10 Correct 887 ms 27288 KB Output is correct
11 Correct 8 ms 11352 KB Output is correct
12 Correct 35 ms 12368 KB Output is correct
13 Execution timed out 5048 ms 32544 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 7 ms 11368 KB Output is correct
5 Correct 6 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11476 KB Output is correct
8 Correct 5 ms 11356 KB Output is correct
9 Correct 5 ms 11452 KB Output is correct
10 Correct 5 ms 11356 KB Output is correct
11 Correct 5 ms 11356 KB Output is correct
12 Correct 5 ms 11444 KB Output is correct
13 Correct 6 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 7 ms 11368 KB Output is correct
5 Correct 6 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11476 KB Output is correct
8 Correct 5 ms 11356 KB Output is correct
9 Correct 5 ms 11452 KB Output is correct
10 Correct 5 ms 11356 KB Output is correct
11 Correct 5 ms 11356 KB Output is correct
12 Correct 5 ms 11444 KB Output is correct
13 Correct 6 ms 11356 KB Output is correct
14 Correct 5 ms 11352 KB Output is correct
15 Correct 5 ms 11356 KB Output is correct
16 Correct 6 ms 11356 KB Output is correct
17 Correct 5 ms 11444 KB Output is correct
18 Correct 6 ms 11448 KB Output is correct
19 Correct 7 ms 11356 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11444 KB Output is correct
22 Correct 5 ms 11400 KB Output is correct
23 Correct 4 ms 11408 KB Output is correct
24 Correct 5 ms 11372 KB Output is correct
25 Correct 5 ms 11356 KB Output is correct
26 Correct 4 ms 11356 KB Output is correct
27 Correct 4 ms 11356 KB Output is correct
28 Correct 7 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 7 ms 11368 KB Output is correct
5 Correct 6 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11476 KB Output is correct
8 Correct 5 ms 11356 KB Output is correct
9 Correct 5 ms 11452 KB Output is correct
10 Correct 5 ms 11356 KB Output is correct
11 Correct 5 ms 11356 KB Output is correct
12 Correct 5 ms 11444 KB Output is correct
13 Correct 6 ms 11356 KB Output is correct
14 Correct 5 ms 11352 KB Output is correct
15 Correct 5 ms 11356 KB Output is correct
16 Correct 6 ms 11356 KB Output is correct
17 Correct 5 ms 11444 KB Output is correct
18 Correct 6 ms 11448 KB Output is correct
19 Correct 7 ms 11356 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11444 KB Output is correct
22 Correct 5 ms 11400 KB Output is correct
23 Correct 4 ms 11408 KB Output is correct
24 Correct 5 ms 11372 KB Output is correct
25 Correct 5 ms 11356 KB Output is correct
26 Correct 4 ms 11356 KB Output is correct
27 Correct 4 ms 11356 KB Output is correct
28 Correct 7 ms 11356 KB Output is correct
29 Correct 7 ms 11352 KB Output is correct
30 Correct 9 ms 11356 KB Output is correct
31 Correct 6 ms 11352 KB Output is correct
32 Correct 7 ms 11356 KB Output is correct
33 Correct 5 ms 11488 KB Output is correct
34 Correct 6 ms 11500 KB Output is correct
35 Correct 6 ms 11356 KB Output is correct
36 Correct 6 ms 11444 KB Output is correct
37 Correct 5 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 7 ms 11368 KB Output is correct
5 Correct 6 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11476 KB Output is correct
8 Correct 5 ms 11356 KB Output is correct
9 Correct 5 ms 11452 KB Output is correct
10 Correct 5 ms 11356 KB Output is correct
11 Correct 5 ms 11356 KB Output is correct
12 Correct 5 ms 11444 KB Output is correct
13 Correct 6 ms 11356 KB Output is correct
14 Correct 5 ms 11352 KB Output is correct
15 Correct 5 ms 11356 KB Output is correct
16 Correct 6 ms 11356 KB Output is correct
17 Correct 5 ms 11444 KB Output is correct
18 Correct 6 ms 11448 KB Output is correct
19 Correct 7 ms 11356 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11444 KB Output is correct
22 Correct 5 ms 11400 KB Output is correct
23 Correct 4 ms 11408 KB Output is correct
24 Correct 5 ms 11372 KB Output is correct
25 Correct 5 ms 11356 KB Output is correct
26 Correct 4 ms 11356 KB Output is correct
27 Correct 4 ms 11356 KB Output is correct
28 Correct 7 ms 11356 KB Output is correct
29 Correct 7 ms 11352 KB Output is correct
30 Correct 9 ms 11356 KB Output is correct
31 Correct 6 ms 11352 KB Output is correct
32 Correct 7 ms 11356 KB Output is correct
33 Correct 5 ms 11488 KB Output is correct
34 Correct 6 ms 11500 KB Output is correct
35 Correct 6 ms 11356 KB Output is correct
36 Correct 6 ms 11444 KB Output is correct
37 Correct 5 ms 11356 KB Output is correct
38 Correct 202 ms 15188 KB Output is correct
39 Correct 919 ms 27216 KB Output is correct
40 Correct 327 ms 13968 KB Output is correct
41 Correct 237 ms 12660 KB Output is correct
42 Correct 139 ms 14244 KB Output is correct
43 Correct 34 ms 12720 KB Output is correct
44 Correct 36 ms 11780 KB Output is correct
45 Correct 973 ms 16468 KB Output is correct
46 Correct 955 ms 16476 KB Output is correct
47 Correct 390 ms 21164 KB Output is correct
48 Correct 386 ms 21136 KB Output is correct
49 Correct 632 ms 16776 KB Output is correct
50 Correct 619 ms 16856 KB Output is correct
51 Correct 154 ms 18192 KB Output is correct
52 Correct 158 ms 18124 KB Output is correct
53 Correct 49 ms 11868 KB Output is correct
54 Correct 693 ms 16552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11228 KB Output is correct
2 Correct 5 ms 11352 KB Output is correct
3 Correct 4 ms 11280 KB Output is correct
4 Correct 5 ms 11356 KB Output is correct
5 Correct 10 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 7 ms 11356 KB Output is correct
8 Correct 7 ms 11356 KB Output is correct
9 Correct 4 ms 11356 KB Output is correct
10 Correct 5 ms 11356 KB Output is correct
11 Correct 4 ms 11356 KB Output is correct
12 Correct 6 ms 11292 KB Output is correct
13 Correct 20 ms 11868 KB Output is correct
14 Correct 27 ms 12196 KB Output is correct
15 Correct 25 ms 11948 KB Output is correct
16 Execution timed out 5051 ms 17072 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 9 ms 11608 KB Output is correct
5 Correct 15 ms 12124 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 5 ms 11236 KB Output is correct
8 Correct 6 ms 11356 KB Output is correct
9 Correct 198 ms 15248 KB Output is correct
10 Correct 887 ms 27288 KB Output is correct
11 Correct 8 ms 11352 KB Output is correct
12 Correct 35 ms 12368 KB Output is correct
13 Execution timed out 5048 ms 32544 KB Time limit exceeded
14 Halted 0 ms 0 KB -