| Task: | Etäisyydet |
| Sender: | lady-stardust |
| Submission time: | 2021-01-23 18:48:59 +0200 |
| Language: | C++ (C++17) |
| 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 |
Compiler report
input/code.cpp: In function 'bool fill(int, std::vector<int>&, int)':
input/code.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (c.size() == n) {
~~~~~~~~~^~~~Code
#include <bits/stdc++.h>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
using namespace std;
bool visited[11];
int dist[11][11];
vector<int> v[11];
void find_distance(int start, int n, int prev, int c) {
dist[start][n] = c;
for (auto x : v[n]) {
if (x != prev) {
find_distance(start, x, n, c+1);
}
}
}
bool fill(int x, vector<int>& c, int n) {
c.push_back(x);
visited[x] = true;
if (c.size() == n) {
return true;
}
for (int i = 1; i <= n; i++) {
if (visited[i]) continue;
if (dist[i][x] > 3) continue;
if (fill(i, c, n)) {
return true;
}
}
visited[x] = false;
c.pop_back();
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// istringstream cin(R"(2
//10
//1 2
//2 3
//3 4
//1 5
//5 6
//6 7
//1 8
//8 9
//9 10
//7
//1 2
//2 3
//3 4
//4 5
//1 6
//6 7)");
ll t; cin >> t;
for (int i = 0; i < t; i++) {
int n; cin >> n;
for (int x = 0; x < 11; x++) {
visited[x] = false;
v[x] = {};
}
for (int j = 0; j < n - 1; j++) {
int a, b; cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int j = 1; j <= n; j++) {
find_distance(j, j, 0, 0);
}
for (int j = 1; j <= n; j++) {
vector<int> c;
fill(j, c, n);
if (c.size()) {
for (auto item : c) {
cout << item << " ";
}
break;
}
}
cout << "\n";
}
}
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) |
