Task: | Tietoverkko |
Sender: | EeliH |
Submission time: | 2021-10-06 23:45:41 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 25 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 15 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.06 s | 2, 3 | details |
#3 | RUNTIME ERROR | 0.24 s | 3 | details |
Compiler report
input/code.cpp: In function 'uint64_t maara(uint64_t, uint64_t)': input/code.cpp:28:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if(naapuri != pois && naapuri != -1) { ~~~~~~~~^~~~~
Code
#include <algorithm>#include <iostream>#include <vector>using namespace std;vector<struct yhteys> yhteydet;vector<uint64_t> naapurit[200000];struct yhteys {uint64_t a;uint64_t b;uint64_t nopeus;bool kayty;};bool a_comp(struct yhteys a, struct yhteys b){return a.nopeus < b.nopeus;}uint64_t maara(uint64_t tietokone, uint64_t pois){uint64_t m = 1;for(uint64_t naapuri: naapurit[tietokone]) {//cout << tietokone << ": " << naapuri << endl;//cout << "MÄÄRÄ " << tietokone << " " << pois << " " << naapuri << endl;if(naapuri != pois && naapuri != -1) {//cout << "OIKEA NAAPURI" << endl;m += maara(naapuri, tietokone);}}return m;}int main(){uint64_t n;cin >> n;for(uint64_t i = 0; i < n - 1; i++) {struct yhteys yhteys;cin >> yhteys.a >> yhteys.b >> yhteys.nopeus;yhteys.kayty = false;yhteydet.push_back(yhteys);naapurit[yhteys.a].push_back(yhteys.b);naapurit[yhteys.b].push_back(yhteys.a);}sort(yhteydet.begin(), yhteydet.end(), a_comp);uint64_t summa = 0;for(struct yhteys yhteys: yhteydet) {uint64_t m1 = maara(yhteys.b, yhteys.a);//remove(naapurit[yhteys.b].begin(), naapurit[yhteys.b].end(), yhteys.a);//remove(naapurit[yhteys.a].begin(), naapurit[yhteys.a].end(), yhteys.b);naapurit[yhteys.b][distance(naapurit[yhteys.b].begin(), find(naapurit[yhteys.b].begin(), naapurit[yhteys.b].end(), yhteys.a))] = -1;naapurit[yhteys.a][distance(naapurit[yhteys.a].begin(), find(naapurit[yhteys.a].begin(), naapurit[yhteys.a].end(), yhteys.b))] = -1;//cout << "A" << yhteys.nopeus << " " << yhteys.b << " " << yhteys.a << " " << r << endl;uint64_t m2 = (maara(yhteys.a, yhteys.b) - 1);uint64_t r = m1 * (m2 + 1) * yhteys.nopeus;//cout << "A" << yhteys.nopeus << " " << yhteys.a << " " << yhteys.b << " " << r << endl;summa += r;}cout << summa << endl;}
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: ACCEPTED
input |
---|
5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1103702320243776 |
user output |
---|
1103702320243776 |
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) |