Submission #35120340
Source Code Expand
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
vector<vector<ll>> G;
stack<ll> ans;
bool dfs(ll now, ll pre,ll dis) {
if (now == dis) {
ans.push(now);
//cout << now << endl;
return 1;
}
bool f = 0;
for (auto v : G[now]) {
if (v == pre)continue;
if (dfs(v, now, dis)) {
ans.push(now);
f = 1;
//cout << now << endl;
}
}
if (f)return 1;
else
return 0;
}
int main(){
ll N, X, Y;
cin >> N >> X >> Y;
G = vector <vector<ll>>(N + 1);
for (int i = 0; i < N - 1; i++) {
ll a, b;
cin >> a >> b;
G[b].push_back(a);
G[a].push_back(b);
}
dfs(X, -1, Y);
while (ans.size()) {
cout << ans.top() << endl;
ans.pop();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Simple path |
| User | amaoto |
| Language | C++ (GCC 9.2.1) |
| Score | 300 |
| Code Size | 842 Byte |
| Status | AC |
| Exec Time | 449 ms |
| Memory | 31328 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 6 ms | 3456 KiB |
| example_01.txt | AC | 2 ms | 3568 KiB |
| hand_00.txt | AC | 2 ms | 3500 KiB |
| hand_01.txt | AC | 447 ms | 31328 KiB |
| hand_02.txt | AC | 122 ms | 15836 KiB |
| hand_03.txt | AC | 442 ms | 31328 KiB |
| hand_04.txt | AC | 449 ms | 31324 KiB |
| random_00.txt | AC | 156 ms | 15196 KiB |
| random_01.txt | AC | 157 ms | 15280 KiB |
| random_02.txt | AC | 162 ms | 15372 KiB |
| random_03.txt | AC | 152 ms | 15376 KiB |
| random_04.txt | AC | 155 ms | 15288 KiB |
| random_05.txt | AC | 154 ms | 15140 KiB |
| random_06.txt | AC | 157 ms | 15376 KiB |
| random_07.txt | AC | 164 ms | 15140 KiB |
| random_08.txt | AC | 162 ms | 15368 KiB |
| random_09.txt | AC | 137 ms | 16324 KiB |
| random_10.txt | AC | 137 ms | 15996 KiB |
| random_11.txt | AC | 136 ms | 16192 KiB |
| random_12.txt | AC | 394 ms | 27980 KiB |
| random_13.txt | AC | 348 ms | 26092 KiB |
| random_14.txt | AC | 364 ms | 27260 KiB |
| random_15.txt | AC | 392 ms | 28512 KiB |
| random_16.txt | AC | 348 ms | 25964 KiB |
| random_17.txt | AC | 169 ms | 20060 KiB |
| random_18.txt | AC | 237 ms | 21272 KiB |
| random_19.txt | AC | 152 ms | 16900 KiB |