답안 #1052625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052625 2024-08-10T17:51:25 Z turska Railway (BOI17_railway) C++17
100 / 100
115 ms 31248 KB
#include <bits/stdc++.h>
using namespace std;
 
#define all(v) (v).begin(), (v).end()

 
int n, m, k;
vector<pair<int, int>> adj[100001];
vector<int> q[100001];
 
int z[100001];
 
vector<int> ans;
 
map<int, int> dfs(int v, int p) {
    map<int, int> a;
 
    for (auto [u, i]: adj[v]) if (u!=p) {
        map<int, int> b = dfs(u, v);
 
        if (b.size()>=k) {
            ans.push_back(i);
        }
 
        if (a.size() < b.size()) a.swap(b);
        for (auto [k, v]: b) {
            if (a[k]+v==z[k]) a.erase(k);
            else a[k] += v;
        }
    }
 
    for (auto u: q[v]) {
        a[u]++;
        if (a[u] == z[u]) a.erase(u);
    }
    return a;
}
 
int main() {
    cin >> n >> m >> k;
 
    for (int i=0; i<n-1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back({v, i});
        adj[v].push_back({u, i});
    }
    for (int i=0; i<m; i++) {
        int s;
        cin >> s;
        z[i] = s;
        for (int j=0; j<s; j++) {
            int k;
            cin >> k;
            q[k].push_back(i);
        }
    }
    dfs(1, 1);
    sort(all(ans));
    cout << ans.size() << '\n';
    for (auto i: ans) cout << i+1 << ' ';
}

Compilation message

railway.cpp: In function 'std::map<int, int> dfs(int, int)':
railway.cpp:21:21: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         if (b.size()>=k) {
      |             ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 4 ms 5724 KB Output is correct
3 Correct 4 ms 5624 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 6 ms 5980 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 4 ms 5724 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5212 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 4 ms 5724 KB Output is correct
3 Correct 4 ms 5624 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 6 ms 5980 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 4 ms 5724 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5212 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 24 ms 6236 KB Output is correct
16 Correct 24 ms 6480 KB Output is correct
17 Correct 24 ms 6488 KB Output is correct
18 Correct 6 ms 6744 KB Output is correct
19 Correct 5 ms 5980 KB Output is correct
20 Correct 27 ms 6644 KB Output is correct
21 Correct 33 ms 6484 KB Output is correct
22 Correct 1 ms 5208 KB Output is correct
23 Correct 5 ms 5764 KB Output is correct
24 Correct 5 ms 5724 KB Output is correct
25 Correct 1 ms 5212 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 5 ms 6748 KB Output is correct
28 Correct 4 ms 5976 KB Output is correct
29 Correct 4 ms 5724 KB Output is correct
30 Correct 4 ms 5724 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 1 ms 5212 KB Output is correct
33 Correct 1 ms 5212 KB Output is correct
34 Correct 1 ms 5212 KB Output is correct
35 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 31112 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 99 ms 30896 KB Output is correct
4 Correct 89 ms 30492 KB Output is correct
5 Correct 78 ms 30412 KB Output is correct
6 Correct 77 ms 30264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 21420 KB Output is correct
2 Correct 83 ms 12884 KB Output is correct
3 Correct 93 ms 14160 KB Output is correct
4 Correct 93 ms 14428 KB Output is correct
5 Correct 102 ms 13512 KB Output is correct
6 Correct 78 ms 21588 KB Output is correct
7 Correct 77 ms 21324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 21420 KB Output is correct
2 Correct 83 ms 12884 KB Output is correct
3 Correct 93 ms 14160 KB Output is correct
4 Correct 93 ms 14428 KB Output is correct
5 Correct 102 ms 13512 KB Output is correct
6 Correct 78 ms 21588 KB Output is correct
7 Correct 77 ms 21324 KB Output is correct
8 Correct 73 ms 21332 KB Output is correct
9 Correct 70 ms 21328 KB Output is correct
10 Correct 72 ms 30160 KB Output is correct
11 Correct 70 ms 30156 KB Output is correct
12 Correct 48 ms 11292 KB Output is correct
13 Correct 48 ms 11092 KB Output is correct
14 Correct 78 ms 10568 KB Output is correct
15 Correct 75 ms 10580 KB Output is correct
16 Correct 102 ms 14400 KB Output is correct
17 Correct 95 ms 14416 KB Output is correct
18 Correct 90 ms 14520 KB Output is correct
19 Correct 83 ms 12884 KB Output is correct
20 Correct 78 ms 21588 KB Output is correct
21 Correct 84 ms 21720 KB Output is correct
22 Correct 85 ms 21840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 4 ms 5724 KB Output is correct
3 Correct 4 ms 5624 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 6 ms 5980 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 4 ms 5724 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5212 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 24 ms 6236 KB Output is correct
16 Correct 24 ms 6480 KB Output is correct
17 Correct 24 ms 6488 KB Output is correct
18 Correct 6 ms 6744 KB Output is correct
19 Correct 5 ms 5980 KB Output is correct
20 Correct 27 ms 6644 KB Output is correct
21 Correct 33 ms 6484 KB Output is correct
22 Correct 1 ms 5208 KB Output is correct
23 Correct 5 ms 5764 KB Output is correct
24 Correct 5 ms 5724 KB Output is correct
25 Correct 1 ms 5212 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 5 ms 6748 KB Output is correct
28 Correct 4 ms 5976 KB Output is correct
29 Correct 4 ms 5724 KB Output is correct
30 Correct 4 ms 5724 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 1 ms 5212 KB Output is correct
33 Correct 1 ms 5212 KB Output is correct
34 Correct 1 ms 5212 KB Output is correct
35 Correct 1 ms 5212 KB Output is correct
36 Correct 115 ms 31112 KB Output is correct
37 Correct 1 ms 5212 KB Output is correct
38 Correct 99 ms 30896 KB Output is correct
39 Correct 89 ms 30492 KB Output is correct
40 Correct 78 ms 30412 KB Output is correct
41 Correct 77 ms 30264 KB Output is correct
42 Correct 79 ms 21420 KB Output is correct
43 Correct 83 ms 12884 KB Output is correct
44 Correct 93 ms 14160 KB Output is correct
45 Correct 93 ms 14428 KB Output is correct
46 Correct 102 ms 13512 KB Output is correct
47 Correct 78 ms 21588 KB Output is correct
48 Correct 77 ms 21324 KB Output is correct
49 Correct 73 ms 21332 KB Output is correct
50 Correct 70 ms 21328 KB Output is correct
51 Correct 72 ms 30160 KB Output is correct
52 Correct 70 ms 30156 KB Output is correct
53 Correct 48 ms 11292 KB Output is correct
54 Correct 48 ms 11092 KB Output is correct
55 Correct 78 ms 10568 KB Output is correct
56 Correct 75 ms 10580 KB Output is correct
57 Correct 102 ms 14400 KB Output is correct
58 Correct 95 ms 14416 KB Output is correct
59 Correct 90 ms 14520 KB Output is correct
60 Correct 83 ms 12884 KB Output is correct
61 Correct 78 ms 21588 KB Output is correct
62 Correct 84 ms 21720 KB Output is correct
63 Correct 85 ms 21840 KB Output is correct
64 Correct 75 ms 21388 KB Output is correct
65 Correct 115 ms 13532 KB Output is correct
66 Correct 98 ms 11764 KB Output is correct
67 Correct 82 ms 11600 KB Output is correct
68 Correct 42 ms 10832 KB Output is correct
69 Correct 42 ms 10844 KB Output is correct
70 Correct 81 ms 22224 KB Output is correct
71 Correct 73 ms 21076 KB Output is correct
72 Correct 1 ms 5212 KB Output is correct
73 Correct 4 ms 5724 KB Output is correct
74 Correct 4 ms 5724 KB Output is correct
75 Correct 1 ms 5212 KB Output is correct
76 Correct 1 ms 5212 KB Output is correct
77 Correct 5 ms 6748 KB Output is correct
78 Correct 7 ms 5980 KB Output is correct
79 Correct 5 ms 5724 KB Output is correct
80 Correct 4 ms 5724 KB Output is correct
81 Correct 1 ms 5212 KB Output is correct
82 Correct 2 ms 5212 KB Output is correct
83 Correct 1 ms 5208 KB Output is correct
84 Correct 1 ms 5212 KB Output is correct
85 Correct 1 ms 5212 KB Output is correct
86 Correct 25 ms 6444 KB Output is correct
87 Correct 25 ms 6492 KB Output is correct
88 Correct 25 ms 6456 KB Output is correct
89 Correct 6 ms 6748 KB Output is correct
90 Correct 4 ms 5980 KB Output is correct
91 Correct 28 ms 6592 KB Output is correct
92 Correct 35 ms 6480 KB Output is correct
93 Correct 1 ms 5212 KB Output is correct
94 Correct 96 ms 31248 KB Output is correct
95 Correct 91 ms 31048 KB Output is correct
96 Correct 90 ms 30548 KB Output is correct
97 Correct 79 ms 30412 KB Output is correct
98 Correct 77 ms 30160 KB Output is correct
99 Correct 106 ms 14672 KB Output is correct
100 Correct 94 ms 14676 KB Output is correct
101 Correct 95 ms 14432 KB Output is correct
102 Correct 83 ms 13136 KB Output is correct
103 Correct 96 ms 21352 KB Output is correct
104 Correct 87 ms 21716 KB Output is correct
105 Correct 79 ms 21332 KB Output is correct
106 Correct 75 ms 21332 KB Output is correct
107 Correct 71 ms 21076 KB Output is correct
108 Correct 72 ms 30148 KB Output is correct
109 Correct 70 ms 30128 KB Output is correct
110 Correct 48 ms 11088 KB Output is correct
111 Correct 50 ms 11092 KB Output is correct
112 Correct 75 ms 10228 KB Output is correct
113 Correct 75 ms 10796 KB Output is correct