제출 #1083093

#제출 시각아이디문제언어결과실행 시간메모리
1083093_8_8_Railway (BOI17_railway)C++17
100 / 100
210 ms124500 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 12, MOD = (int)1e9 + 7; int n, s[N], m, k, res[N], val[N]; vector<pair<int,int>> g[N]; vector<int> c[N]; map<int,int> col[N]; void dfs(int v, int pr = -1, int pid = 0) { int f = 0; for(auto [to,i]:g[v]) { if(to == pr) continue; dfs(to, v, i); if((int)col[to].size() > (int)col[v].size()) { swap(f,res[i]); col[to].swap(col[v]); } for(auto [x,y]:col[to]) { if(!col[v].count(x)) { f++; } col[v][x] += y; if(col[v][x] == s[x]) { f--; } } } for(auto j:c[v]) { col[v][j]++; if(col[v][j] == 1) { f++; } if(col[v][j] == s[j]) { f--; } } val[pid] = res[pid] = f; } void test() { cin >> n >> m >> k; for(int i = 1; i <= n - 1; i++) { int a, b; cin >> a >> b; g[a].push_back({b,i}); g[b].push_back({a,i}); } for(int i = 1; i <= m; i++) { cin >> s[i]; for(int j = 0; j < s[i]; j++) { int x; cin >> x; if((int)c[x].size() && c[x].back() == i) continue; c[x].push_back(i); } } dfs(1); vector<int> ans; for(int i = 1; i <= n - 1; i++) { // cout << i << ' ' << res[i] << '\n'; if(val[i] >= k) { ans.push_back(i); } } cout << (int)ans.size() << '\n'; for(auto i:ans) { cout << i << ' '; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); 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...