제출 #480700

#제출 시각아이디문제언어결과실행 시간메모리
480700hidden1Railway (BOI17_railway)C++14
29 / 100
1090 ms21872 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #define endl "\n" typedef long long ll; template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;} template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;} template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; #ifndef LOCAL #define cerr if(false) cerr #endif const int MAX_N = 1e5 + 10, MAX_LOG = 20;; vector<pair<int, int> > g[MAX_N]; int par[MAX_N][MAX_LOG]; int d[MAX_N]; int ind[MAX_N], cnt[MAX_N]; vector<int> ans; int n, m, k; void dfs(int x, int p) { par[x][0] = p; for(int i = 1; i < MAX_LOG; i ++) { par[x][i] = par[par[x][i - 1]][i - 1]; } d[x] = d[p] + 1; for(auto it : g[x]) { if(it.first == p) {continue;} ind[it.first] = it.second; dfs(it.first, x); } } int lca(int a, int b) { if(d[a] < d[b]) {swap(a, b);} for(int i = MAX_LOG - 1; i >= 0; i --) { if(d[par[a][i]] >= d[b]) { a = par[a][i]; } } if(a == b) {return a;} for(int i = MAX_LOG - 1; i >= 0; i --) { if(par[a][i] != par[b][i]) { a = par[a][i]; b = par[b][i]; } } return par[a][0]; } int calc(int x, int p) { int now = cnt[x]; for(auto it : g[x]) { if(it.first == p) {continue;} now += calc(it.first, x); } if(now >= k) { ans.push_back(ind[x]); } return now; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> k; for(int i = 0; i < n - 1; i ++) { int a, b; cin >> a >> b; g[a].push_back({b, i + 1}); g[b].push_back({a, i + 1}); } dfs(1, 0); for(int i = 0; i < m; i ++) { int lst; cin >> lst; vector<int> a(lst); for(int j = 0; j < lst; j ++) { cin >> a[j]; for(int small = 0; small < j; small ++) { int l = lca(a[j], a[small]); cnt[a[j]] ++; cnt[a[small]] ++; cnt[l] -= 2; } } } calc(1, 0); sort(ans.begin(), ans.end()); cout << ans.size() << endl; for(auto it : ans) { cout << it << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...