This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "speedrun.h"
// #include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define alr(a) a.rbegin(), a.rend()
int n;
vector < vector < int >> adj;
void dfs(int node, int par) {
vector < int > arr;
for(auto ch : adj[node]) {
arr.push_back(ch);
if(ch == par) continue;
dfs(ch, node);
}
vector < int > val(n + 1);
for(auto i : arr) val[i] = 1;
for(int i = 1 ; i <= n ; i++) {
setHint(node, i, val[i]);
}
}
void assignHints(int subtask, int N, int A[], int B[]) {
n = N;
adj = vector < vector < int >> (n + 2);
setHintLen(n);
for(int i = 1 ; i < n ; i++) {
int u = A[i], v = B[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 1);
}
void solve(int node, int par) {
for(int i = 1 ; i <= n ; i++) {
if(i == par) continue;
if(getHint(i) == 1) {
goTo(i);
// cout << node << " -> " << i << endl;
solve(i, node);
}
}
if(par != node) {
// cout << node << " -> " << par << endl;
goTo(par);
}
}
void speedrun(int subtask, int N, int st) {
n = N;
solve(st, st);
}
# | 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... |