This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll L = 20;
const ll N = 1e5 + 50;
const ll Mod = 1e9 + 7;
ll n, m, k, st[N], timer, h[N], par[N][L], id[N], cnt[N];
vector<pii> adj[N];
void dfs(int v, int p = 0){
par[v][0] = p;
for(int i = 1; i < L; i++){
if(!par[v][i-1]) break;
par[v][i] = par[par[v][i-1]][i-1];
}
st[v] = ++timer;
for(auto [u, i]: adj[v]){
if(u == p) continue;
h[u] = h[v] + 1; id[i] = u;
dfs(u, v);
}
}
int getPar(int v, int x){
for(int i = 0; i < L; i++){
if(x >> i & 1) v = par[v][i];
}
return v;
}
int lca(int v, int u){
if(h[v] < h[u]) swap(u, v);
v = getPar(v, h[v] - h[u]);
if(u == v) return v;
for(int i = L-1; i >= 0; i--){
if(par[v][i] != par[u][i]){
v = par[v][i]; u = par[u][i];
}
}
return par[v][0];
}
void cal(int v){
for(auto [u, i]: adj[v]){
if(u == par[v][0]) continue;
cal(u); cnt[v] += cnt[u];
}
}
int main(){
fast_io;
cin >> n >> m >> k;
int u, v;
for(int i = 1; i < n; i++){
cin >> u >> v;
adj[u].pb(Mp(v, i));
adj[v].pb(Mp(u, i));
}
dfs(1);
while(m--){
int si; cin >> si;
set<pii> ver;
for(int i = 1; i <= si; i++){
cin >> v; ver.insert({st[v], v});
}
while(ver.size() > 1){
auto lst1 = *ver.rbegin(); ver.erase(lst1);
auto lst2 = *ver.rbegin();
int l = lca(lst1.S, lst2.S);
cnt[lst1.S]++; cnt[l]--;
ver.insert({st[l], l});
}
}
//for(int i = 1; i <= n; i++) cout << cnt[i] << sep;
cal(1);
int res = 0;
for(int i = 1; i < n; i++) if(cnt[id[i]] >= k) res++;
cout << res << endl;
for(int i = 1; i < n; i++) if(cnt[id[i]] >= k) cout << i << sep;
}
Compilation message (stderr)
railway.cpp: In function 'void dfs(int, int)':
railway.cpp:42:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto [u, i]: adj[v]){
| ^
railway.cpp: In function 'void cal(int)':
railway.cpp:70:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | for(auto [u, i]: adj[v]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |