Task: | Tietoverkko |
Sender: | jusola |
Submission time: | 2021-10-12 20:57:44 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 10 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.03 s | 1, 2, 3 | details |
#2 | TIME LIMIT EXCEEDED | -- | 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, vector<int> sps, int &res, vector<int> &vis2) { if (find(cr.begin(), cr.end(), pair<int,int>(v,ov)) == cr.end() && find(cr.begin(), cr.end(), pair<int,int>(ov,v)) == cr.end() && ov != v){ int msp = *min_element(sps.begin(), sps.end()); res += msp; //cout << ov << " to " << v << " msp " << msp << " tot " << res << "\n"; //cout << " "; //for (auto i: sps) // std::cout << i << ' '; //cout << "\n"; cr.push_back({ov, v}); } for (auto p: g[v]) { int u = p.first; int sp = p.second; if(find(vis2.begin(), vis2.end(), u) == vis2.end() && ov != u){ vis2.push_back(u); vector<int> nsps; nsps = sps; nsps.push_back(sp); s2(ov, u, g, cr, nsps, 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, vector<int>(), 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[5001]; int n; 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}); } //for(int si = 1; si <= n; si++){ vector<pair<int, int>> cr; vector<int> vis; int res = 0; s(1, g, cr, res, vis); cout << res << "\n"; //} return 0; }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
88687 |
Test 2
Group: 2, 3
Verdict: TIME LIMIT EXCEEDED
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) |