Submission #1052625

#TimeUsernameProblemLanguageResultExecution timeMemory
1052625turskaRailway (BOI17_railway)C++17
100 / 100
115 ms31248 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() int n, m, k; vector<pair<int, int>> adj[100001]; vector<int> q[100001]; int z[100001]; vector<int> ans; map<int, int> dfs(int v, int p) { map<int, int> a; for (auto [u, i]: adj[v]) if (u!=p) { map<int, int> b = dfs(u, v); if (b.size()>=k) { ans.push_back(i); } if (a.size() < b.size()) a.swap(b); for (auto [k, v]: b) { if (a[k]+v==z[k]) a.erase(k); else a[k] += v; } } for (auto u: q[v]) { a[u]++; if (a[u] == z[u]) a.erase(u); } return a; } int main() { cin >> n >> m >> k; for (int i=0; i<n-1; i++) { int u, v; cin >> u >> v; adj[u].push_back({v, i}); adj[v].push_back({u, i}); } for (int i=0; i<m; i++) { int s; cin >> s; z[i] = s; for (int j=0; j<s; j++) { int k; cin >> k; q[k].push_back(i); } } dfs(1, 1); sort(all(ans)); cout << ans.size() << '\n'; for (auto i: ans) cout << i+1 << ' '; }

Compilation message (stderr)

railway.cpp: In function 'std::map<int, int> dfs(int, int)':
railway.cpp:21:21: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         if (b.size()>=k) {
      |             ~~~~~~~~^~~
#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...