| Task: | Tietoverkko |
| Sender: | intoo |
| Submission time: | 2021-10-04 20:41:53 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 25 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 15 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.10 s | 2, 3 | details |
| #3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'll dfs(int, int)':
input/code.cpp:40:17: warning: unused variable 'w' [-Wunused-variable]
for (auto [y, w] : adj[x]) {
^Code
#include <iostream>
#include <set>
#include <queue>
#include <tuple>
using namespace std;
using ll = long long;
set<pair<int, int>> adj[200200];
priority_queue<tuple<int, int, int>> q;
ll dfs(int x, int e);
int main()
{
int n;
cin >> n;
for (int i = 1; i < n; ++i) {
int a, b, x;
cin >> a >> b >> x;
adj[a].emplace(b, x);
adj[b].emplace(a, x);
q.emplace(-x, a, b);
}
ll s = 0;
while (!q.empty()) {
auto [x, a, b] = q.top();
x = -x;
q.pop();
adj[a].erase({b, x});
adj[b].erase({a, x});
s += dfs(a, b) * dfs(b, a) * x;
}
cout << s << endl;
}
ll dfs(int x, int e)
{
int k = 1;
for (auto [y, w] : adj[x]) {
if (y == e) continue;
k += dfs(y, x);
}
return k;
}
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: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
| correct output |
|---|
| 1080549209850010931 |
| user output |
|---|
| (empty) |
