| Task: | Distances |
| Sender: | pidddgy |
| Submission time: | 2021-01-31 18:33:56 +0200 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 29 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 29 |
| #2 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2 | details |
| #2 | RUNTIME ERROR | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h>
using namespace std;
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ld long double
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define y1 lsdjkfhshfdsighoihweogihewoghi
#define all(x) (x).begin(), (x).end()
const int maxn = 10;
int n;
int dis[maxn][maxn];
vector<int> G[maxn];
void bfs(int st) {
queue<int> Q;
Q.push(st);
dis[st][st] = 0;
watch(st)
while(!Q.empty()) {
int S = Q.front(); Q.pop();
watch(S)
for(int to: G[S]) {
watch(to)
if(dis[st][to] > dis[st][S]+1) {
Q.push(to);
dis[st][to] = dis[st][S]+1;
}
}
}
cerr << endl << endl;
}
void solve() {
for(int i = 0; i < maxn; i++) {
for(int j = 0; j < maxn; j++) {
dis[i][j] = 1e18;
}
G[i].clear();
}
cin >> n;
for(int i = 1; i <= n-1; i++) {
int u, v;
cin >> u >> v;
G[u].emplace_back(v);
G[v].emplace_back(u);
}
for(int i = 1; i <= n; i++) bfs(i);
vector<int> v;
for(int i = 1; i <= n; i++) v.push_back(i);
watch(dis[1][2])
watch(dis[2][3])
watch(dis[3][4])
do {
bool f = false;
for(int i = 1; i < sz(v); i++) {
if(dis[v[i]][v[i-1]] > 3) f = true;
}
if(!f) {
for(int x: v) {
cout << x << " ";
}
cout << endl;
return;
}
} while(next_permutation(all(v)));
cout << "none" << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) solve();
}
/*
*/
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper?
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 100 8 5 2 2 3 3 7 ... |
| correct output |
|---|
| 1 8 2 5 6 7 3 4 1 7 2 8 3 6 4 5 1 4 6 2 7 5 8 3 1 8 3 2 4 7 6 5 1 6 4 7 5 2 3 8 ... |
| user output |
|---|
| 1 3 2 4 7 5 6 8 1 3 2 8 7 5 4 6 1 3 2 5 7 8 6 4 1 2 3 4 5 6 7 8 1 3 2 4 6 8 7 5 ... Truncated |
Test 2
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 37 59 81 37 44 81 ... |
| correct output |
|---|
| 1 99 82 81 59 5 71 55 17 24 13... |
| user output |
|---|
| (empty) |
