이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector <pair<int, int>> g[N];
int timer, tin[N], tout[N], up[N][18];
void dfs(int v, int p = 1) {
tin[v] = ++timer;
up[v][0] = p;
for (int i = 1; i <= 17; i++) up[v][i] = up[up[v][i - 1]][i - 1];
for (pair<int, int> to : g[v]) {
if (to.first != p) {
dfs(to.first, v);
}
}
tout[v] = timer;
}
bool upper(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v) {
if (upper(u, v)) return u;
if (upper(v, u)) return v;
for (int i = 17; i >= 0; i--) {
if (!upper(up[u][i], v)) {
u = up[u][i];
}
}
return up[u][0];
}
bool cmp(int u, int v) {
return tin[u] < tin[v];
}
int cnt[N], dp[N];
void dfs2(int v, int p = 1, int edg = 0) {
for (pair<int, int> to : g[v]) {
if (to.first != p) {
dfs2(to.first, v, to.second);
dp[v] += dp[to.first];
}
}
cnt[edg] = dp[v];
}
int main(){
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(make_pair(v, i));
g[v].push_back(make_pair(u, i));
}
dfs(1);
for (int i = 1; i <= m; i++) {
int s;
cin >> s;
vector <int> S(s);
for (int &a : S) {
cin >> a;
}
sort(S.begin(), S.end(), cmp);
for (int i = 0; i < S.size() - 1; i++) {
int u = S[i], v = S[i + 1];
int L = lca(u, v);
dp[v]++;
dp[L]--;
}
}
dfs2(1);
vector <int> ans;
for (int i = 1; i < n; i++) {
if (cnt[i] >= k) {
ans.push_back(i);
}
}
cout << ans.size() << "\n";
for (int edg : ans) cout << edg << " ";
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp: In function 'int main()':
railway.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < S.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
# | 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... |