QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283859#5421. Factories Once MorebobbilykingWA 19ms13464kbC++171.5kb2023-12-15 17:02:002023-12-15 17:02:00

Judging History

你现在查看的是最新测评结果

  • [2023-12-15 17:02:00]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:13464kb
  • [2023-12-15 17:02:00]
  • 提交

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 smhlf = (k)/2;
        
        smhlf = min(smhlf, smol);
        ans += w * smhlf * (k - smhlf);
        
        // 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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8280kb

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: 2ms
memory: 8420kb

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: 8368kb

input:

2 2
1 2 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Wrong Answer
time: 19ms
memory: 13464kb

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'