Submission #1052628

#TimeUsernameProblemLanguageResultExecution timeMemory
1052628turskaRailway (BOI17_railway)C++17
100 / 100
116 ms31244 KiB
#include <bits/stdc++.h> using namespace std; int n, m, k, u, v, s, h; #define P push_back #define N 100001 vector<pair<int, int>> adj[N]; vector<int> q[N]; int z[N]; vector<int> A; 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) { A.P(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++) { cin >> u >> v; adj[u].P({v, i}); adj[v].P({u, i}); } for (int i=0; i<m; i++) { cin >> s; z[i] = s; for (int j=0; j<s; j++) { cin >> h; q[h].P(i); } } dfs(1, 1); sort(A.begin(), A.end()); cout << A.size() << '\n'; for (auto i: A) cout << i+1 << ' '; }

Compilation message (stderr)

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