Task: | Tietoverkko |
Sender: | mooc.fi~486604 |
Submission time: | 2021-10-05 17:39:54 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.35 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.07 s | 2, 3 | details |
#3 | RUNTIME ERROR | 0.27 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:49:9: warning: unused variable 'ocounter' [-Wunused-variable] int ocounter=-1; ^~~~~~~~
Code
#include <bits/stdc++.h> using namespace std; int N; vector<pair<int,int>> v[200000]; long long int minsum; long long int sum; int vasen=0; int oikea= 0; int alku; int loppu; void haku(int s, int e, int target){ vasen++; oikea++; // cout<<" 3"; for(auto u: v[s]){ if(u.first!=e&&u.second>target) haku(u.first, s, target); if(u.first!=e&&u.second==target){ int temp1=vasen; int temp2=oikea; vasen=0; haku(e, s, target); // cout<<"vasen "<<vasen<<endl; int temp=vasen; oikea=0; haku(loppu, alku, target); //cout<<"oikea "<<oikea<<endl; minsum+=temp*oikea*target; // cout<<"minsum "<<minsum<<endl; vasen=temp1; oikea=temp2; } } } int main() { long long int i, a,b,c; sum=0; minsum=0; int ocounter=-1; cin>>N; vector<vector<long long int>> di; for(i=0; i<N-1; i++){ cin>>a>>b>>c; di.push_back({a,b,c}); v[a].push_back({b,c}); v[b].push_back({a,c}); } for(auto kl: di){ vasen=0; alku=kl[0]; loppu=kl[1]; //cout<<"1"; haku(kl[0], kl[1] , kl[2]); int kpp=vasen; oikea=0; alku=kl[1]; loppu=kl[0]; haku(kl[1], kl[0], kl[2]); // cout<<"2"; //cout<<kl[2]*(juu*oikea)<<endl; sum+= kl[2]*kpp*oikea; } // cout<<"minsum "<<minsum<<" "<<sum<<endl; cout<<sum+(minsum/2); return 0; }
Test details
Test 1
Group: 1, 2, 3
Verdict: RUNTIME ERROR
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
(empty) |
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) |
Error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc