답안 #575609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575609 2022-06-11T06:44:37 Z InternetPerson10 Jail (JOI22_jail) C++17
61 / 100
5000 ms 254756 KB
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<vector<int>> adj;
vector<bool> taken;
vector<vector<int>> val;
vector<vector<int>> paths;
vector<vector<int>> adjm;
vector<int> inDeg;

bool dfs(int n, int tar) {
    taken[n] = true;
    if(n == tar) {
        paths.back().push_back(n);
        return true;
    }
    for(int ch : adj[n]) {
        if(taken[ch]) continue;
        if(dfs(ch, tar)) {
            paths.back().push_back(n);
            return true;
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        adj.resize(n);
        taken.resize(n);
        for(int i = 1; i < n; i++) {
            int x, y;
            cin >> x >> y;
            x--; y--;
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
        int m;
        cin >> m;
        val.resize(n, vector<int>());
        adjm.resize(m, vector<int>());
        inDeg.resize(m);
        for(int i = 0; i < m; i++) {
            paths.push_back(vector<int>());
            int x, y;
            cin >> x >> y;
            dfs(x-1, y-1);
            for(int j = 0; j < n; j++) {
                taken[j] = false;
            }
            reverse(paths[i].begin(), paths[i].end());
            val[paths[i].front()].push_back(i+1);
            val[paths[i].back()].push_back(-(i+1));
        }
        for(int i = 0; i < m; i++) {
            for(int g : paths[i]) {
                for(int z : val[g]) {
                    int x = i;
                    int y = abs(z) - 1;
                    if(x == y) continue;
                    if(z > 0) swap(x, y);
                    adjm[x].push_back(y);
                    inDeg[y]++;
                }
            }
        }
        queue<int> q;
        int movedP = 0;
        for(int i = 0; i < m; i++) {
            if(inDeg[i] == 0) q.push(i);
        }
        while(q.size()) {
            movedP++;
            int g = q.front(); q.pop();
            for(int k : adjm[g]) {
                inDeg[k]--;
                if(inDeg[k] == 0) {
                    q.push(k);
                }
            }
        }
        bool ok = (movedP == m);
        cout << (ok ? "Yes\n" : "No\n");
        val.clear();
        adj.clear();
        paths.clear();
        taken.clear();
        adjm.clear();
        inDeg.clear();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 13 ms 680 KB Output is correct
5 Correct 30 ms 732 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 556 KB Output is correct
9 Correct 510 ms 17816 KB Output is correct
10 Correct 2163 ms 254556 KB Output is correct
11 Correct 9 ms 440 KB Output is correct
12 Correct 98 ms 1468 KB Output is correct
13 Execution timed out 5092 ms 24164 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 2 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 1 ms 340 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 1 ms 340 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 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 1 ms 364 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 1 ms 340 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 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 1 ms 364 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 8 ms 520 KB Output is correct
30 Correct 5 ms 400 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 1 ms 340 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 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 1 ms 364 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 8 ms 520 KB Output is correct
30 Correct 5 ms 400 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 494 ms 17648 KB Output is correct
39 Correct 2013 ms 254756 KB Output is correct
40 Correct 631 ms 5060 KB Output is correct
41 Correct 658 ms 1812 KB Output is correct
42 Correct 380 ms 5320 KB Output is correct
43 Correct 65 ms 2076 KB Output is correct
44 Correct 91 ms 788 KB Output is correct
45 Correct 1609 ms 11568 KB Output is correct
46 Correct 1671 ms 11648 KB Output is correct
47 Correct 784 ms 55840 KB Output is correct
48 Correct 850 ms 57756 KB Output is correct
49 Correct 1114 ms 14060 KB Output is correct
50 Correct 1092 ms 14012 KB Output is correct
51 Correct 276 ms 12184 KB Output is correct
52 Correct 303 ms 12516 KB Output is correct
53 Correct 77 ms 1236 KB Output is correct
54 Correct 1580 ms 11468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 9 ms 468 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 48 ms 868 KB Output is correct
14 Correct 61 ms 1080 KB Output is correct
15 Correct 57 ms 960 KB Output is correct
16 Execution timed out 5079 ms 12072 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 13 ms 680 KB Output is correct
5 Correct 30 ms 732 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 556 KB Output is correct
9 Correct 510 ms 17816 KB Output is correct
10 Correct 2163 ms 254556 KB Output is correct
11 Correct 9 ms 440 KB Output is correct
12 Correct 98 ms 1468 KB Output is correct
13 Execution timed out 5092 ms 24164 KB Time limit exceeded
14 Halted 0 ms 0 KB -