제출 #1096686

#제출 시각아이디문제언어결과실행 시간메모리
1096686nguyenvuRailway (BOI17_railway)C++14
0 / 100
44 ms23624 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int n,m,k; vector<int> a[500007]; map<pair<int,int>,int> mp; int d[500007]; namespace sub1 { bool check() { return 1; } bool f[500007]; vector<pair<int,int>> res; int dfs(int i) { f[i] = 1; bool ok = (d[i]>=k); for (const int &j : a[i]) { if (f[j]) continue; if (dfs(j)) { res.push_back(pair<int,int>(min(i,j),max(i,j))); ok = 1; } } return ok; } void solve() { for (int i=1; i<=n; i++) { if (f[i]) continue; if (d[i] < k) continue; dfs(i); } for (pair<int,int> &i : res) { i.first = mp[i]; } sort(res.begin(),res.end()); cout << res.size() << '\n'; for (const pair<int,int> &i : res) cout << i.first << ' '; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i=1; i<n; i++) { int u,v; cin >> u >> v; a[u].push_back(v); a[v].push_back(u); mp[pair<int,int>(min(u,v),max(u,v))] = i; } for (int i=1; i<=n; i++) { sort(a[i].begin(),a[i].end()); } for (int i=1; i<=m; i++) { int x; cin >> x; while (x--) { int t; cin >> t; d[t]++; } } if (sub1::check()) { sub1::solve(); return 0; } 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...