Submission #758790

# Submission time Handle Problem Language Result Execution time Memory
758790 2023-06-15T10:06:57 Z Hacv16 Railway (BOI17_railway) C++17
100 / 100
127 ms 47620 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int

const int LOG = 22;
const int MAX = 5e5 + 10;
const int INF = 0x3f3f3f3f;
 
int n, m, k, f[MAX], dp[MAX][LOG], h[MAX], tin[MAX], a[MAX], timer;
vector<pair<int, int>> adj[MAX];
vector<int> ids;

void dfs(int u, int p){
	tin[u] = ++timer;
	dp[u][0] = p; h[u] = h[p] + 1;

   	for(int i = 1; i < LOG; i++)
        dp[u][i] = dp[ dp[u][i - 1] ][i - 1];

	for(auto [v, id] : adj[u]){
		if(v == p) continue;
		dfs(v, u);
	}
}

int lca(int u, int v){
	if(h[u] < h[v]) swap(u, v);
	int jump = h[u] - h[v];
 
	for(int j = LOG - 1; j >= 0; j--)
		if(jump & (1 << j)) u = dp[u][j];
 
	if(u == v) return v;
 
	for(int j = LOG - 1; j >= 0; j--)
		if(dp[u][j] != dp[v][j]) u = dp[u][j], v = dp[v][j];
 
	return dp[u][0];
}

void calcResp(int u, int p, int id){
    for(auto [v, nx] : adj[u]){
        if(v == p) continue;
        calcResp(v, u, nx);
        f[u] += f[v];
    }

    if(f[u] >= k * 2 && id != 0)
    	ids.push_back(id);
}

int32_t main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m >> k;

	for(int i = 1; i < n; i++){
		int u, v; cin >> u >> v;

		adj[u].emplace_back(v, i);
		adj[v].emplace_back(u, i);
	}
	
	dfs(1, 0);
    
	for(int i = 1; i <= m; i++){
        int n; cin >> n;
        for(int i = 1; i <= n; i++)
           cin >> a[i];

        sort(a + 1, a + n + 1, [&](int i, int j){
        	return tin[i] < tin[j];
        });

        a[n + 1] = a[1];

        for (int i = 1; i <= n; i++) {
            f[a[i]]++; f[a[i + 1]]++;
            f[lca(a[i], a[i + 1])] -= 2;
        }
    }

	calcResp(1, 0, 0);

	cout << ids.size() << '\n';

	sort(ids.begin(), ids.end());
	for(auto x : ids) cout << x << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12072 KB Output is correct
2 Correct 12 ms 14564 KB Output is correct
3 Correct 11 ms 14592 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12076 KB Output is correct
6 Correct 11 ms 15176 KB Output is correct
7 Correct 11 ms 14760 KB Output is correct
8 Correct 10 ms 14548 KB Output is correct
9 Correct 11 ms 14644 KB Output is correct
10 Correct 6 ms 12072 KB Output is correct
11 Correct 6 ms 12076 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12048 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12072 KB Output is correct
2 Correct 12 ms 14564 KB Output is correct
3 Correct 11 ms 14592 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12076 KB Output is correct
6 Correct 11 ms 15176 KB Output is correct
7 Correct 11 ms 14760 KB Output is correct
8 Correct 10 ms 14548 KB Output is correct
9 Correct 11 ms 14644 KB Output is correct
10 Correct 6 ms 12072 KB Output is correct
11 Correct 6 ms 12076 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12048 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 24 ms 15024 KB Output is correct
16 Correct 27 ms 15104 KB Output is correct
17 Correct 26 ms 15100 KB Output is correct
18 Correct 12 ms 15060 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 28 ms 15164 KB Output is correct
21 Correct 30 ms 15036 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 11 ms 14612 KB Output is correct
24 Correct 10 ms 14676 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 12096 KB Output is correct
27 Correct 11 ms 15156 KB Output is correct
28 Correct 11 ms 14772 KB Output is correct
29 Correct 10 ms 14548 KB Output is correct
30 Correct 10 ms 14676 KB Output is correct
31 Correct 6 ms 12072 KB Output is correct
32 Correct 6 ms 12076 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 5 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 47132 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 109 ms 46648 KB Output is correct
4 Correct 105 ms 45884 KB Output is correct
5 Correct 100 ms 47188 KB Output is correct
6 Correct 95 ms 47620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 42456 KB Output is correct
2 Correct 100 ms 39032 KB Output is correct
3 Correct 94 ms 38476 KB Output is correct
4 Correct 108 ms 38484 KB Output is correct
5 Correct 96 ms 38488 KB Output is correct
6 Correct 81 ms 42704 KB Output is correct
7 Correct 93 ms 42552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 42456 KB Output is correct
2 Correct 100 ms 39032 KB Output is correct
3 Correct 94 ms 38476 KB Output is correct
4 Correct 108 ms 38484 KB Output is correct
5 Correct 96 ms 38488 KB Output is correct
6 Correct 81 ms 42704 KB Output is correct
7 Correct 93 ms 42552 KB Output is correct
8 Correct 103 ms 42636 KB Output is correct
9 Correct 100 ms 42668 KB Output is correct
10 Correct 91 ms 47360 KB Output is correct
11 Correct 89 ms 47284 KB Output is correct
12 Correct 91 ms 37696 KB Output is correct
13 Correct 96 ms 37760 KB Output is correct
14 Correct 93 ms 38452 KB Output is correct
15 Correct 95 ms 38480 KB Output is correct
16 Correct 96 ms 38580 KB Output is correct
17 Correct 127 ms 38564 KB Output is correct
18 Correct 91 ms 38476 KB Output is correct
19 Correct 92 ms 38996 KB Output is correct
20 Correct 87 ms 42880 KB Output is correct
21 Correct 110 ms 42996 KB Output is correct
22 Correct 96 ms 42864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12072 KB Output is correct
2 Correct 12 ms 14564 KB Output is correct
3 Correct 11 ms 14592 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12076 KB Output is correct
6 Correct 11 ms 15176 KB Output is correct
7 Correct 11 ms 14760 KB Output is correct
8 Correct 10 ms 14548 KB Output is correct
9 Correct 11 ms 14644 KB Output is correct
10 Correct 6 ms 12072 KB Output is correct
11 Correct 6 ms 12076 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12048 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 24 ms 15024 KB Output is correct
16 Correct 27 ms 15104 KB Output is correct
17 Correct 26 ms 15100 KB Output is correct
18 Correct 12 ms 15060 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 28 ms 15164 KB Output is correct
21 Correct 30 ms 15036 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 11 ms 14612 KB Output is correct
24 Correct 10 ms 14676 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 12096 KB Output is correct
27 Correct 11 ms 15156 KB Output is correct
28 Correct 11 ms 14772 KB Output is correct
29 Correct 10 ms 14548 KB Output is correct
30 Correct 10 ms 14676 KB Output is correct
31 Correct 6 ms 12072 KB Output is correct
32 Correct 6 ms 12076 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 5 ms 11988 KB Output is correct
36 Correct 109 ms 47132 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 109 ms 46648 KB Output is correct
39 Correct 105 ms 45884 KB Output is correct
40 Correct 100 ms 47188 KB Output is correct
41 Correct 95 ms 47620 KB Output is correct
42 Correct 93 ms 42456 KB Output is correct
43 Correct 100 ms 39032 KB Output is correct
44 Correct 94 ms 38476 KB Output is correct
45 Correct 108 ms 38484 KB Output is correct
46 Correct 96 ms 38488 KB Output is correct
47 Correct 81 ms 42704 KB Output is correct
48 Correct 93 ms 42552 KB Output is correct
49 Correct 103 ms 42636 KB Output is correct
50 Correct 100 ms 42668 KB Output is correct
51 Correct 91 ms 47360 KB Output is correct
52 Correct 89 ms 47284 KB Output is correct
53 Correct 91 ms 37696 KB Output is correct
54 Correct 96 ms 37760 KB Output is correct
55 Correct 93 ms 38452 KB Output is correct
56 Correct 95 ms 38480 KB Output is correct
57 Correct 96 ms 38580 KB Output is correct
58 Correct 127 ms 38564 KB Output is correct
59 Correct 91 ms 38476 KB Output is correct
60 Correct 92 ms 38996 KB Output is correct
61 Correct 87 ms 42880 KB Output is correct
62 Correct 110 ms 42996 KB Output is correct
63 Correct 96 ms 42864 KB Output is correct
64 Correct 91 ms 42772 KB Output is correct
65 Correct 111 ms 38564 KB Output is correct
66 Correct 125 ms 38388 KB Output is correct
67 Correct 101 ms 38432 KB Output is correct
68 Correct 75 ms 37648 KB Output is correct
69 Correct 89 ms 37608 KB Output is correct
70 Correct 94 ms 43112 KB Output is correct
71 Correct 102 ms 42384 KB Output is correct
72 Correct 6 ms 12076 KB Output is correct
73 Correct 11 ms 14676 KB Output is correct
74 Correct 13 ms 14676 KB Output is correct
75 Correct 7 ms 12204 KB Output is correct
76 Correct 8 ms 11988 KB Output is correct
77 Correct 12 ms 15188 KB Output is correct
78 Correct 11 ms 14680 KB Output is correct
79 Correct 10 ms 14512 KB Output is correct
80 Correct 10 ms 14676 KB Output is correct
81 Correct 6 ms 12068 KB Output is correct
82 Correct 6 ms 11988 KB Output is correct
83 Correct 6 ms 11988 KB Output is correct
84 Correct 6 ms 12000 KB Output is correct
85 Correct 6 ms 11988 KB Output is correct
86 Correct 25 ms 15024 KB Output is correct
87 Correct 25 ms 15060 KB Output is correct
88 Correct 25 ms 15156 KB Output is correct
89 Correct 12 ms 15272 KB Output is correct
90 Correct 11 ms 14788 KB Output is correct
91 Correct 31 ms 15208 KB Output is correct
92 Correct 31 ms 15052 KB Output is correct
93 Correct 6 ms 11988 KB Output is correct
94 Correct 109 ms 47172 KB Output is correct
95 Correct 105 ms 46660 KB Output is correct
96 Correct 89 ms 45936 KB Output is correct
97 Correct 101 ms 47100 KB Output is correct
98 Correct 115 ms 47588 KB Output is correct
99 Correct 96 ms 38532 KB Output is correct
100 Correct 100 ms 38540 KB Output is correct
101 Correct 93 ms 38468 KB Output is correct
102 Correct 98 ms 38972 KB Output is correct
103 Correct 82 ms 42588 KB Output is correct
104 Correct 86 ms 42992 KB Output is correct
105 Correct 85 ms 42424 KB Output is correct
106 Correct 119 ms 42772 KB Output is correct
107 Correct 105 ms 42576 KB Output is correct
108 Correct 89 ms 47352 KB Output is correct
109 Correct 99 ms 47288 KB Output is correct
110 Correct 85 ms 37804 KB Output is correct
111 Correct 78 ms 37768 KB Output is correct
112 Correct 103 ms 38492 KB Output is correct
113 Correct 101 ms 38416 KB Output is correct