QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283863 | #5421. Factories Once More | bobbilyking | WA | 25ms | 13800kb | C++17 | 1.6kb | 2023-12-15 17:05:19 | 2023-12-15 17:05:20 |
Judging History
answer
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define NN 200010
#define M 1000000007 // 998244353
ll n, k;
vector<pl> adj[NN];
ll ans = 0;
ll dfs(ll i, ll p) {
ll sz = 0;
for (auto [x, w]: adj[i]) if (x-p) {
ll child = dfs(x, i);
ll smol = child, large = n-child;
if (smol > large) swap(smol, large);
ll bst = 0;
// F(mid, max(0ll, k/2-5), min(k/2+5, k)+1)
F(mid, 0, k+1)
{
ll smhlf = min(mid, smol);
bst = max(bst, w * smhlf * (k - smhlf));
}
ans += bst;
// cout << "WTF " << w << " " << smhlf << " " << k-smhlf << " , " << i << " -> " << x << " , " << w << endl;
sz += child;
}
return sz+1;
}
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
cin >> n >> k;
F(i, 0, n-1) {
G(x) G(y) G(w) adj[x].emplace_back(y, w); adj[y].emplace_back(x, w);
}
dfs(1, 1);
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8320kb
input:
6 3 1 2 3 2 3 2 2 4 1 1 5 2 5 6 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8376kb
input:
4 3 1 2 2 1 3 3 1 4 4
output:
18
result:
ok 1 number(s): "18"
Test #3:
score: 0
Accepted
time: 2ms
memory: 8320kb
input:
2 2 1 2 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 25ms
memory: 13800kb
input:
100000 17 37253 35652 9892 56367 53643 1120 47896 49255 4547 93065 88999 1745 5251 6742 5031 49828 50972 8974 31548 46729 1032 56341 56287 4812 21896 22838 1682 82124 90557 7307 76289 76949 7028 33834 45380 6856 15499 15064 2265 10127 5251 9920 87208 93945 9487 68990 72637 6891 91640 85004 2259 4748...
output:
18593074788
result:
wrong answer 1st numbers differ - expected: '4915539756', found: '18593074788'