CSES - Datatähti 2021 loppu - Results
Submission details
Task:Etäisyydet
Sender:Guuber
Submission time:2021-01-23 18:07:58 +0200
Language:C++ (C++17)
Status:READY
Result:29
Feedback
groupverdictscore
#1ACCEPTED29
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2--2details

Code

#include<bits/stdc++.h>
using namespace std;
vector<int> graph[101010];
vector<int> graph2[101010];
int d[101][101];
int z[101][101];
int main(){
int t;
cin >> t;
while(t--){
for(int i = 0; i < 101; i++){
graph[i] = {};
graph2[i] = {};
for(int j = 0; j < 101; j++){
d[i][j] = 0;
z[i][j] = 0;
}
}
int n;
cin >> n;
for(int i = 0; i < n-1; i++){
int a,b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for(int i = 1; i <= n; i++){
z[i][i] = 1;
d[i][i] = 0;
queue<int> q = {};
q.push(i);
while(!q.empty()){
int s = q.front(); q.pop();
for(auto u : graph[s]){
if(z[i][u]) continue;
z[i][u] = 1; d[i][u] = d[i][s] + 1;
q.push(u);
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
// cout << i << "," << j << ": " << d[i][j] << "\n";
}
}
vector<int> ve = {};
for(int i = 1; i <= n; i++){
ve.push_back(i);
}
do{
bool bo = false;
for(int i = 1; i < n; i++){
if(d[ve[i]][ve[i-1]] > 3){
bo = true;
break;
}
}
if(!bo){
for(auto u : ve){
cout << u << " ";
}
cout << "\n";
break;
}
} while(next_permutation(ve.begin(), ve.end()));
}
}

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:

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)