이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
int n, m, k;
vector<int> adj[100001];
vector<int> q[100001];
int z[100001];
vector<int> ans;
map<pair<int, int>, int> e;
map<int, int> dfs(int v, int p) {
map<int, int> a;
for (auto u: adj[v]) {
if (u==p) continue;
map<int, int> b = dfs(u, v);
if (b.size()>=k) {
ans.push_back(e[{v, u}]);
}
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);
adj[v].push_back(u);
e[{u, v}] = i+1;
e[{v, u}] = i+1;
}
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 << ' ';
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp: In function 'std::map<int, int> dfs(int, int)':
railway.cpp:22:21: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if (b.size()>=k) {
| ~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |