Task: | Etäisyydet |
Sender: | AtskaFin |
Submission time: | 2021-01-23 16:56:49 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.14 s | 2 | details |
Compiler report
input/code.cpp: In function 'void search(int)': input/code.cpp:76:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (answer.size() == n) { ~~~~~~~~~~~~~~^~~~
Code
#include <iostream> #include <algorithm> #include <vector> typedef long long ll; using namespace std; int n; vector<vector<int>> vieruslista; ll d[101][101]; ll v[101][101]; int z[101]; void calculateDistances() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i==j) d[i][j] = 0; else if (v[i][j]) d[i][j] = v[i][j]; else d[i][j] = 1e18; } } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { d[i][j] = min(d[i][j], d[i][k]+d[k][j]); } } } } void readValues() { cin >> n; vieruslista.clear(); vieruslista.resize(n+1); for (int i = 0; i < 101; i++) z[i] = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { v[i][j] = 0; v[j][i] = 0; d[i][j] = 0; d[j][i] = 0; } } for (int i = 0; i < n-1; i++) { int a, b; cin>>a>>b; vieruslista[a].push_back(b); vieruslista[b].push_back(a); v[a][b] = 1; v[b][a] = 1; } } vector<int> answer; bool found = false; void search(int s) { if (found) return; answer.push_back(s); z[s] = 1; //cout << "here " << s << "\n"; //for (int x : answer) cout << x << " "; //cout << "\n"; if (answer.size() == n) { found = true; for (int x : answer) cout << x << " "; cout << "\n"; //cout << "found"; return; } for (int u : vieruslista[s]) { //cout << "Solmu " << u << "\n"; if (z[u]) continue; //cout << "Solmujen etäisyys " << d[s][u] << "\n"; if (d[s][u] <= 3) { //cout << "Etsitään " << u << "\n"; search(u); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; for (int i = 0; i < t; i++) { readValues(); calculateDistances(); answer.clear(); found = false; search(1); } }
Test details
Test 1
Group: 1, 2
Verdict: WRONG ANSWER
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 4 8 3 2 5 6 7 1 3 7 8 2 5 6 4 1 4 3 6 8 2 7 5 1 6 8 3 2 4 7 5 1 6 8 4 3 7 2 5 ... Truncated |
Test 2
Group: 2
Verdict: WRONG ANSWER
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
1 22 99 60 82 44 81 37 59 17 5... Truncated |