Submission #606824

#TimeUsernameProblemLanguageResultExecution timeMemory
606824HanksburgerRailway (BOI17_railway)C++17
100 / 100
219 ms34212 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[100005]; map<int, int> mp[100005]; int s[100005], n, m, k; vector<int> ans; void dfs(int u, int p, int ind) { for (int i=0; i<adj[u].size(); i++) { int v=adj[u][i].first, w=adj[u][i].second; if (v!=p) { dfs(v, u, w); if (mp[u].size()<mp[v].size()) mp[u].swap(mp[v]); for (auto itr=mp[v].begin(); itr!=mp[v].end(); itr++) { mp[u][itr->first]+=itr->second; if (mp[u][itr->first]==s[itr->first]) mp[u].erase(itr->first); } } } if (mp[u].size()>=k) ans.push_back(ind); } int main() { ios::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; adj[u].push_back({v, i}); adj[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, 1, 0); cout << ans.size() << '\n'; sort(ans.begin(), ans.end()); for (int i:ans) cout << i << ' '; return 0; }

Compilation message (stderr)

railway.cpp: In function 'void dfs(int, int, int)':
railway.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i=0; i<adj[u].size(); i++)
      |                   ~^~~~~~~~~~~~~~
railway.cpp:25:21: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (mp[u].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...