Task: | Tietoverkko |
Sender: | jusola |
Submission time: | 2021-10-12 20:01:21 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#2 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
#3 | RUNTIME ERROR | 0.01 s | 3 | details |
Code
#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #define ll long long using namespace std; void s2(int ov, int v, vector<pair<int, int>> *g, vector<pair<int, int>> &cr, int cm, int &res, vector<int> &vis2) { for (auto p: g[v]) { int u = p.first; int sp = p.second; if(find(vis2.begin(), vis2.end(), u) == vis2.end() && v != u && ov != u){ if (find(cr.begin(), cr.end(), pair<int,int>(u,ov)) == cr.end() && find(cr.begin(), cr.end(), pair<int,int>(ov,u)) == cr.end()){ if (cm == -1) cm = sp; if (sp < cm){ res += sp; }else{ res += cm; } cr.push_back({ov, u}); //cout << "route: " << ov << " to " << u << " via " << v << " ls " << sp << " cm: " << cm << " total: " << res <<"\n"; } vis2.push_back(u); if (sp < cm){ s2(ov, u, g, cr, sp, res, vis2); }else{ s2(ov, u, g, cr, cm, res, vis2); } } } } void s(int v, vector<pair<int, int>> *g, vector<pair<int, int>> &cr, int &res, vector<int> &vis){ vector<int> vis2; s2(v, v, g, cr, -1, res, vis2); for (auto p: g[v]) { int u = p.first; if(find(vis.begin(), vis.end(), u) == vis.end()){ vis.push_back(u); s(u, g, cr, res, vis); } } } int main() { vector<pair<int, int>> g[101]; vector<pair<int, int>> cr; vector<int> vis; int n, res=0; cin >> n; for(int i=0; i<(n-1); i++){ int a,b,sp; cin >> a >> b >> sp; g[a].push_back({b,sp}); g[b].push_back({a,sp}); } s(1, g, cr, res, vis); cout << res; return 0; }
Test details
Test 1
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
107915 |
Test 2
Group: 2, 3
Verdict: RUNTIME ERROR
input |
---|
5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1103702320243776 |
user output |
---|
(empty) |
Test 3
Group: 3
Verdict: RUNTIME ERROR
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
(empty) |