제출 #495510

#제출 시각아이디문제언어결과실행 시간메모리
495510hoanghq2004Railway (BOI17_railway)C++14
100 / 100
181 ms39368 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 << ' '; }

컴파일 시 표준 에러 (stderr) 메시지

railway.cpp: In function 'void dfs(int, int, int)':
railway.cpp:14:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |     for (auto [v, id]: e[u]) {
      |               ^
railway.cpp:18:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |         for (auto [i, x]: mp[v]) {
      |                   ^
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...