Submission #952092

#TimeUsernameProblemLanguageResultExecution timeMemory
952092Trisanu_DasRailway (BOI17_railway)C++17
100 / 100
159 ms39608 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e5 + 10; int n, m, k; unordered_map <int, int> mp[Nmax]; vector <pair <int, int> > e[Nmax]; int s[Nmax]; vector <int> ans; void dfs(int u, int p, int ide) { for (auto [v, id]: e[u]) { if (v == p) continue; dfs(v, u, id); if (mp[u].size() < mp[v].size()) mp[u].swap(mp[v]); for (auto [i, x]: mp[v]) { mp[u][i] += x; if (mp[u][i] == s[i]) mp[u].erase(i); } } if (mp[u].size() >= k) ans.push_back(ide); } int main() { ios :: sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; e[u].push_back({v, i}); e[v].push_back({u, i}); } for (int i = 1; i <= m; ++i) { cin >> s[i]; for (int j = 1; j <= s[i]; ++j) { int u; cin >> u; ++mp[u][i]; } } dfs(1, 0, 0); cout << ans.size() << '\n'; sort(ans.begin(), ans.end()); for (auto id: ans) cout << id << ' '; }

Compilation message (stderr)

railway.cpp: In function 'void dfs(int, int, int)':
railway.cpp:23:22: warning: comparison of integer expressions of different signedness: 'std::unordered_map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     if (mp[u].size() >= k) ans.push_back(ide);
      |         ~~~~~~~~~~~~~^~~~
#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...