Task: | Tietoverkko |
Sender: | cowperso |
Submission time: | 2021-10-15 16:00:05 +0300 |
Language: | C++ (C++11) |
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.17 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream> #include <vector> #include <utility> #include <unordered_map> using namespace std; static vector<vector<pair<uint32_t, uint64_t>>> puu; static unordered_map<uint64_t, uint64_t> muistio; static uint64_t hitaammat(uint32_t s, uint32_t e, uint64_t vert) { vector<pair<uint32_t, uint32_t>> stack; stack.push_back({s, e}); uint64_t summa = 0; while (!stack.empty()) { auto newval = stack.back(); s = newval.first; e = newval.second; stack.pop_back(); for (auto& seur : puu[s]) { if (seur.first == e) continue; if (seur.second < vert) continue; uint64_t key = (uint64_t)seur.first << 32 | (uint64_t)s; auto muistioviite = muistio.find(key); if (muistioviite == muistio.end() || seur.second != vert + 1) { ++summa; stack.push_back({seur.first, s}); } else { summa += muistioviite->second + 1; } } } muistio[(uint64_t)s << 32 | (uint64_t)e] = summa; return summa; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); uint64_t n; cin >> n; puu.reserve(n); unordered_map<uint32_t, uint32_t> count; for (uint32_t i = 0; i < n - 1; ++i) { uint32_t a, b; uint64_t nopeus; cin >> a >> b >> nopeus; puu[a - 1].push_back({b - 1, 200001 * nopeus + count[n]}); puu[b - 1].push_back({a - 1, 200001 * nopeus + count[n]}); ++count[n]; } uint64_t summa = 0; for (uint32_t i = 0; i < n; ++i) { for (auto& solmu : puu[i]) { if (i > solmu.first) continue; summa += (hitaammat(solmu.first, i, solmu.second) + 1) * (hitaammat(i, solmu.first, solmu.second) + 1) * (solmu.second / 200001); } } cout << summa << '\n'; }
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) |