Task: | Distances |
Sender: | andr1y |
Submission time: | 2021-01-30 15:02:54 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 29 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:34:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation] for(ll i = 1;i<=n;i++) cout<<p[i]<<' ';cout<<'\n'; ^~~ input/code.cpp:34:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for' for(ll i = 1;i<=n;i++) cout<<p[i]<<' ';cout<<'\n'; ^~~~
Code
// -- // #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 120; vector<ll> d[N]; ll p[N]; ll dp[N][N], n; void dfs(ll v, ll p, ll sv, ll len){ dp[sv][v]=len; for(auto i : d[v]){ if(i!=p) dfs(i, v, sv, len+1); } } signed main(){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0); ll q; cin >> q; while(q--){ cin >> n; for(ll i = 1;i<=n;i++) d[i].clear(), p[i]=i; for(ll a, b, i=1;i<n;i++){ cin >> a >> b; d[a].push_back(b); d[b].push_back(a); } for(ll i = 1;i<=n;i++) dfs(i, -1, i, 0); do{ bool ok =1; for(ll i = 2;i<=n;i++){ ok=ok&&dp[p[i-1]][p[i]]<4; } if(ok){ for(ll i = 1;i<=n;i++) cout<<p[i]<<' ';cout<<'\n'; break; } }while(next_permutation(p+1, p+n+1)); } }
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: TIME LIMIT EXCEEDED
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) |