| Task: | Tietoverkko |
| Sender: | Totska |
| Submission time: | 2021-10-12 10:07:12 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | WRONG ANSWER | 0.02 s | 2, 3 | details |
| #3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool sortcol( const vector<int>& v1,
const vector<int>& v2 ) {
return v1[2] > v2[2];
}
int id(int x, vector<int> edustajat){
while(x != edustajat[x]) x = edustajat[x];
return x;
}
int main()
{
int n, u, v, w;
cin >> n;
vector<vector<int>> edges;
vector<int> edustajat;
vector<int> koot;
edustajat.resize(n+1);
koot.resize(n+1);
for (int i = 0; i < n+1; i++) {
edustajat[i] = i;
koot[i] = 1;
}
for (int i = 0; i < n-1; i++) {
cin >> u >> v >> w;
vector<int> e;
e.push_back(u);
e.push_back(v);
e.push_back(w);
edges.push_back(e);
}
sort(edges.begin(), edges.end(), sortcol);
int ans = 0;
int a, b;
for (auto x: edges) {
a = id(x[0], edustajat);
b = id(x[1], edustajat);
ans += x[2] * koot[a] * koot[b];
if (koot[a] > koot[b]){
swap(a, b);
}
edustajat[a] = b;
koot[b] += koot[a];
}
cout << ans << 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: WRONG ANSWER
| input |
|---|
| 5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
| correct output |
|---|
| 1103702320243776 |
| user output |
|---|
| -1195613120 |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
| correct output |
|---|
| 1080549209850010931 |
| user output |
|---|
| (empty) |
