QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#715595 | #3281. Agamemnon's Odyssey | andahe | WA | 32ms | 14672kb | C++20 | 1.2kb | 2024-11-06 12:44:12 | 2024-11-06 12:44:12 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define LL __int128_t
#define PB push_back
#define Pair pair<int, int>
#define MK make_pair
#define fi first
#define se second
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i >= _##i; --i)
#define debug(x) cout<< "\033 -> "<<#x<<": "<<x<<endl
using namespace std;
const int N(200005);
#define X first
#define W second
#define Pair pair<int, int>
vector<Pair> e[N];
int f[N], ans2;
void dfs(int x, int fa)
{
int lk1 = 0, lk2 = 0;
for(auto &to : e[x]) if(to.X != fa)
{
dfs(to.X, x);
if(f[to.X]+to.W > lk1)
{
lk2 = lk1;
lk1 = f[to.X]+to.W;
}
else if(f[to.X]+to.W > lk2) lk2 = f[to.X]+to.W;
}
f[x] = lk1;
ans2 = max(ans2, lk1 + lk2);
}
int main()
{
//freopen("1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, k; cin >> n >> k;
ll ans = 0;
FOR(i, 1, n-1)
{
int x, y, w; cin >> x >> y >> w;
ans += w;
e[x].PB(MK(y, w));
e[y].PB(MK(x, w));
}
if(k >= 2)
{
cout<<ans<<endl;
return 0;
}
dfs(1, 0);
cout<<ans2<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
5 1 1 2 3 2 3 1 1 4 5 1 5 9
output:
14
result:
ok single line: '14'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
5 2 1 2 3 2 3 1 1 4 5 1 5 9
output:
18
result:
ok single line: '18'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
20 1 15 14 911 14 8 739 15 5 365 14 1 326 14 17 718 8 10 964 8 13 398 1 3 336 17 20 702 15 11 185 10 19 631 11 6 1070 3 4 246 4 9 557 1 2 623 10 18 688 20 7 728 6 12 302 18 16 57
output:
4916
result:
ok single line: '4916'
Test #4:
score: 0
Accepted
time: 24ms
memory: 14060kb
input:
99999 1 88646 87257 6 87257 43525 7 43525 64834 7 64834 91293 1 91293 31261 5 31261 4397 7 4397 23402 4 23402 62172 7 62172 28021 3 28021 39342 2 39342 31776 2 31776 20096 3 20096 72671 1 72671 7201 7 7201 99299 5 99299 93287 5 93287 69821 1 69821 35282 5 35282 59207 3 59207 16310 5 16310 67368 1 67...
output:
399896
result:
ok single line: '399896'
Test #5:
score: -100
Wrong Answer
time: 32ms
memory: 14672kb
input:
111111 1 21986 3534 838088783 3534 21378 205896980 21378 79887 707349315 79887 18925 743429185 18925 50642 754437243 50642 71806 83274407 71806 3032 226582377 3032 54854 681487302 54854 76264 226778457 76264 87107 475015146 87107 106546 382826117 106546 65581 90503779 65581 32201 471553349 32201 109...
output:
2147460840
result:
wrong answer 1st lines differ - expected: '52423465374709', found: '2147460840'