CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:voventa
Submission time:2021-01-31 15:59:07 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void dfs(long long int)':
input/code.cpp:44:10: error: 'i' was not declared in this scope
     dfs2(i, 0);
          ^

Code

#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(a) (int)a.size()
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
void solve();
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
vector <int> g[110];
bitset <110> b, uncolor;
vector <int> pans;
void dfs2(int v, int d, int pr = -1) {
if (d == 2 && !b[v]) {
uncolor[v] = 1;
return;
}
for (auto u : g[v]) {
if (u != pr && !b[u])
dfs2(u, d + 1, v);
}
}
void dfs(int v) {
if (!uncolor[v])
pans.pb(v + 1);
b[v] = 1;
dfs2(i, 0);
for (auto i : g[v]) {
if (!b[i]) {
dfs(i);
}
}
if (uncolor[v])
pans.pb(v + 1);
}
void solve() {
b = 0;
uncolor = 0;
int n, x, y;
cin >> n;
for (int i = 0; i < n; ++i) {
g[i].clear();
}
pans.clear();
for (int i = 0; i < n - 1; ++i) {
cin >> x >> y;
x--;
y--;
g[x].pb(y);
g[y].pb(x);
}
dfs(0);
for (auto i : pans) {
cout << i << " ";
}
cout << '\n';
return;
}