Submission #378259

# Submission time Handle Problem Language Result Execution time Memory
378259 2021-03-16T10:53:24 Z Nima_Naderi Railway (BOI17_railway) C++14
100 / 100
262 ms 33756 KB
///In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 1e5 + 10;
const ll LOG = 17;
ll n, q, m, k, timer;
ll Stm[MXN], val[MXN];
ll Jad[LOG][MXN], dis[MXN];
vector<pair<ll, ll>> Edge;
vector<ll> adj[MXN], S, ANS;
void prep(ll u, ll par){
	Jad[0][u] = par, Stm[u] = ++ timer;
	for(int i = 1; i < LOG; i ++) Jad[i][u] = Jad[i - 1][Jad[i - 1][u]];
	for(auto v : adj[u]){
		if(v != par) dis[v] = dis[u] + 1, prep(v, u);
	}
}
ll K_Jad(ll u, ll k){
	for(int i = 0; i < LOG; i ++){
		if((k >> i) & 1LL) u = Jad[i][u];
	}
	return u;
}
ll LCA(ll u, ll v){
	if(dis[u] > dis[v]) swap(u, v);
	v = K_Jad(v, dis[v] - dis[u]);
	if(u == v) return u;
	for(int i = LOG - 1; ~i; i --){
		if(Jad[i][u] != Jad[i][v]){
			u = Jad[i][u], v = Jad[i][v];
		}
	}
	return Jad[0][u];
}
void Add(ll u, ll v){
	ll lca = LCA(u, v);
	val[u] ++, val[v] ++, val[lca] -= 2;
	//cout << "Q : " << u << ' ' << v << " -> " << lca << '\n';
}
void Arch(){
	sort(S.begin(), S.end(), [&](const int &u, const int &v){
		return Stm[u] < Stm[v];
	});
	for(int i = 0; i < m - 1; i ++) Add(S[i], S[i + 1]);
	Add(S[0], S[m - 1]);
}
void flood(ll u, ll par){
	for(auto v : adj[u]){
		if(v != par){
			flood(v, u);
			val[u] += val[v];
		}
	}
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	cin >> n >> q >> k; k *= 2;
	for(int i = 1; i < n; i ++){
		ll u, v; cin >> u >> v;
		adj[u].push_back(v), adj[v].push_back(u);
		Edge.push_back({u, v});
	}
	prep(1, 0);
	//for(int i = 1; i <= n; i ++) cout << Stm[i] << ' '; cout << '\n';
	for(int i = 1; i <= q; i ++){
		S.clear(); cin >> m;
		for(int j = 0; j < m; j ++){
			ll u; cin >> u;
			S.push_back(u);
		}
		Arch();
	}
	flood(1, 0);
	int id = 0;
	for(auto e : Edge){
		ll u, v; tie(u, v) = e; id ++;
		if(dis[u] > dis[v]) swap(u, v);
		if(val[v] >= k) ANS.push_back(id);
	}
	cout << ANS.size() << '\n';
	for(auto X : ANS) cout << X << ' ';
	cout << '\n';
	return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 7 ms 4968 KB Output is correct
3 Correct 8 ms 4968 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 8 ms 5352 KB Output is correct
7 Correct 8 ms 5096 KB Output is correct
8 Correct 7 ms 4968 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 2 ms 2796 KB Output is correct
13 Correct 2 ms 2796 KB Output is correct
14 Correct 2 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 7 ms 4968 KB Output is correct
3 Correct 8 ms 4968 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 8 ms 5352 KB Output is correct
7 Correct 8 ms 5096 KB Output is correct
8 Correct 7 ms 4968 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 2 ms 2796 KB Output is correct
13 Correct 2 ms 2796 KB Output is correct
14 Correct 2 ms 2796 KB Output is correct
15 Correct 33 ms 5352 KB Output is correct
16 Correct 33 ms 5480 KB Output is correct
17 Correct 36 ms 5480 KB Output is correct
18 Correct 8 ms 5352 KB Output is correct
19 Correct 8 ms 5096 KB Output is correct
20 Correct 46 ms 5612 KB Output is correct
21 Correct 47 ms 5480 KB Output is correct
22 Correct 2 ms 2796 KB Output is correct
23 Correct 8 ms 4968 KB Output is correct
24 Correct 8 ms 4968 KB Output is correct
25 Correct 2 ms 2796 KB Output is correct
26 Correct 2 ms 2816 KB Output is correct
27 Correct 9 ms 5352 KB Output is correct
28 Correct 8 ms 5096 KB Output is correct
29 Correct 7 ms 5100 KB Output is correct
30 Correct 8 ms 4968 KB Output is correct
31 Correct 2 ms 2796 KB Output is correct
32 Correct 2 ms 2796 KB Output is correct
33 Correct 2 ms 2796 KB Output is correct
34 Correct 2 ms 2796 KB Output is correct
35 Correct 2 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 33244 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 111 ms 32348 KB Output is correct
4 Correct 109 ms 31068 KB Output is correct
5 Correct 132 ms 33244 KB Output is correct
6 Correct 118 ms 33756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 28508 KB Output is correct
2 Correct 124 ms 25820 KB Output is correct
3 Correct 162 ms 25440 KB Output is correct
4 Correct 151 ms 25440 KB Output is correct
5 Correct 159 ms 25440 KB Output is correct
6 Correct 100 ms 28764 KB Output is correct
7 Correct 97 ms 28636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 28508 KB Output is correct
2 Correct 124 ms 25820 KB Output is correct
3 Correct 162 ms 25440 KB Output is correct
4 Correct 151 ms 25440 KB Output is correct
5 Correct 159 ms 25440 KB Output is correct
6 Correct 100 ms 28764 KB Output is correct
7 Correct 97 ms 28636 KB Output is correct
8 Correct 156 ms 28764 KB Output is correct
9 Correct 152 ms 28764 KB Output is correct
10 Correct 101 ms 33372 KB Output is correct
11 Correct 102 ms 33372 KB Output is correct
12 Correct 236 ms 25184 KB Output is correct
13 Correct 239 ms 25312 KB Output is correct
14 Correct 160 ms 25440 KB Output is correct
15 Correct 178 ms 25432 KB Output is correct
16 Correct 158 ms 25568 KB Output is correct
17 Correct 150 ms 25696 KB Output is correct
18 Correct 148 ms 25668 KB Output is correct
19 Correct 133 ms 25820 KB Output is correct
20 Correct 98 ms 29148 KB Output is correct
21 Correct 99 ms 29532 KB Output is correct
22 Correct 104 ms 29156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 7 ms 4968 KB Output is correct
3 Correct 8 ms 4968 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 8 ms 5352 KB Output is correct
7 Correct 8 ms 5096 KB Output is correct
8 Correct 7 ms 4968 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 2 ms 2796 KB Output is correct
13 Correct 2 ms 2796 KB Output is correct
14 Correct 2 ms 2796 KB Output is correct
15 Correct 33 ms 5352 KB Output is correct
16 Correct 33 ms 5480 KB Output is correct
17 Correct 36 ms 5480 KB Output is correct
18 Correct 8 ms 5352 KB Output is correct
19 Correct 8 ms 5096 KB Output is correct
20 Correct 46 ms 5612 KB Output is correct
21 Correct 47 ms 5480 KB Output is correct
22 Correct 2 ms 2796 KB Output is correct
23 Correct 8 ms 4968 KB Output is correct
24 Correct 8 ms 4968 KB Output is correct
25 Correct 2 ms 2796 KB Output is correct
26 Correct 2 ms 2816 KB Output is correct
27 Correct 9 ms 5352 KB Output is correct
28 Correct 8 ms 5096 KB Output is correct
29 Correct 7 ms 5100 KB Output is correct
30 Correct 8 ms 4968 KB Output is correct
31 Correct 2 ms 2796 KB Output is correct
32 Correct 2 ms 2796 KB Output is correct
33 Correct 2 ms 2796 KB Output is correct
34 Correct 2 ms 2796 KB Output is correct
35 Correct 2 ms 2796 KB Output is correct
36 Correct 117 ms 33244 KB Output is correct
37 Correct 2 ms 2796 KB Output is correct
38 Correct 111 ms 32348 KB Output is correct
39 Correct 109 ms 31068 KB Output is correct
40 Correct 132 ms 33244 KB Output is correct
41 Correct 118 ms 33756 KB Output is correct
42 Correct 99 ms 28508 KB Output is correct
43 Correct 124 ms 25820 KB Output is correct
44 Correct 162 ms 25440 KB Output is correct
45 Correct 151 ms 25440 KB Output is correct
46 Correct 159 ms 25440 KB Output is correct
47 Correct 100 ms 28764 KB Output is correct
48 Correct 97 ms 28636 KB Output is correct
49 Correct 156 ms 28764 KB Output is correct
50 Correct 152 ms 28764 KB Output is correct
51 Correct 101 ms 33372 KB Output is correct
52 Correct 102 ms 33372 KB Output is correct
53 Correct 236 ms 25184 KB Output is correct
54 Correct 239 ms 25312 KB Output is correct
55 Correct 160 ms 25440 KB Output is correct
56 Correct 178 ms 25432 KB Output is correct
57 Correct 158 ms 25568 KB Output is correct
58 Correct 150 ms 25696 KB Output is correct
59 Correct 148 ms 25668 KB Output is correct
60 Correct 133 ms 25820 KB Output is correct
61 Correct 98 ms 29148 KB Output is correct
62 Correct 99 ms 29532 KB Output is correct
63 Correct 104 ms 29156 KB Output is correct
64 Correct 121 ms 29020 KB Output is correct
65 Correct 200 ms 25440 KB Output is correct
66 Correct 262 ms 25440 KB Output is correct
67 Correct 206 ms 25440 KB Output is correct
68 Correct 164 ms 25184 KB Output is correct
69 Correct 175 ms 25184 KB Output is correct
70 Correct 129 ms 29708 KB Output is correct
71 Correct 155 ms 28508 KB Output is correct
72 Correct 2 ms 2796 KB Output is correct
73 Correct 8 ms 4968 KB Output is correct
74 Correct 8 ms 4968 KB Output is correct
75 Correct 3 ms 2796 KB Output is correct
76 Correct 2 ms 2796 KB Output is correct
77 Correct 8 ms 5352 KB Output is correct
78 Correct 8 ms 5096 KB Output is correct
79 Correct 7 ms 4968 KB Output is correct
80 Correct 7 ms 4968 KB Output is correct
81 Correct 2 ms 2796 KB Output is correct
82 Correct 2 ms 2796 KB Output is correct
83 Correct 2 ms 2796 KB Output is correct
84 Correct 2 ms 2796 KB Output is correct
85 Correct 2 ms 2796 KB Output is correct
86 Correct 35 ms 5352 KB Output is correct
87 Correct 45 ms 5480 KB Output is correct
88 Correct 36 ms 5480 KB Output is correct
89 Correct 8 ms 5352 KB Output is correct
90 Correct 8 ms 5096 KB Output is correct
91 Correct 42 ms 5612 KB Output is correct
92 Correct 50 ms 5480 KB Output is correct
93 Correct 3 ms 2800 KB Output is correct
94 Correct 116 ms 33244 KB Output is correct
95 Correct 113 ms 32364 KB Output is correct
96 Correct 112 ms 31204 KB Output is correct
97 Correct 139 ms 33244 KB Output is correct
98 Correct 107 ms 33660 KB Output is correct
99 Correct 179 ms 25440 KB Output is correct
100 Correct 157 ms 25440 KB Output is correct
101 Correct 149 ms 25440 KB Output is correct
102 Correct 138 ms 25952 KB Output is correct
103 Correct 102 ms 28728 KB Output is correct
104 Correct 102 ms 29404 KB Output is correct
105 Correct 95 ms 28508 KB Output is correct
106 Correct 161 ms 29020 KB Output is correct
107 Correct 155 ms 28784 KB Output is correct
108 Correct 100 ms 33372 KB Output is correct
109 Correct 99 ms 33516 KB Output is correct
110 Correct 234 ms 25328 KB Output is correct
111 Correct 247 ms 25184 KB Output is correct
112 Correct 167 ms 25576 KB Output is correct
113 Correct 162 ms 25440 KB Output is correct