QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186368 | #2169. 'S No Problem | So_Stuffy# | WA | 1ms | 6384kb | C++20 | 1.7kb | 2023-09-23 18:24:19 | 2023-09-23 18:24:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 500;
int D[N], pr[N];
vector <pair <int, int> > g[N];
int n;
map <pair <int, int>, int> d, bad, d1;
int bfs(int start) {
for (int i = 1; i <= n; i++) {
D[i] = 1e18;
pr[i] = -1;
}
D[start] = 0;
set <pair <int, int> > q;
q.insert({0, start});
while ((int)q.size()) {
int v = q.begin() -> second; q.erase(q.begin());
for (auto [to, w] : g[v]) {
int W = d1[{v, to}];
if (D[to] > D[v] + W) {
D[to] = D[v] + W;
pr[to] = v;
q.insert({D[to], to});
}
}
}
int mx = 1;
for (int i = 1; i <= n; i++) {
if (D[i] > D[mx]) {
mx = i;
}
}
return mx;
}
int restore(int end) {
int sum = 0;
while (end != -1) {
int from = pr[end];
bad[{from, end}] = bad[{end, from}] = 1;
sum += d[{from, end}];
d1[{from, end}] = 0;
d1[{end, from}] = 0;
end = from;
}
return sum;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b, w;
cin >> a >> b >> w;
d[{a, b}] = w;
d1[{a, b}] = w;
d[{b, a}] = w;
d1[{b, a}] = w;
g[a].push_back({b, w});
g[b].push_back({a, w});
}
int a = bfs(1);
int b = bfs(a);
int ans = 0;
ans += restore(b);
a = bfs(1);
b = bfs(a);
ans += restore(b);
int sum = 0;
for (auto [p, v] : d) {
if (bad.count(p)) {
continue;
}
sum += v;
}
cout << ans + sum;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5800kb
input:
5 1 2 1 1 3 2 1 4 3 1 5 4
output:
10
result:
ok single line: '10'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 6384kb
input:
6 6 2 1 4 6 1 3 1 1 1 5 1 1 6 10
output:
24
result:
wrong answer 1st lines differ - expected: '15', found: '24'