QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487301#6350. MITucup-team2307#WA 2ms9868kbC++202.5kb2024-07-22 19:58:532024-07-22 19:58:53

Judging History

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

  • [2024-07-22 19:58:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9868kb
  • [2024-07-22 19:58:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

int n;
vector<pair<int, int> > g[100500];
int sz[100500];

int dfs1(int v, int p, int W)
{
    sz[v] = W;
    for (auto [i, w] : g[v])
        if (i != p)
            sz[v] += dfs1(i, v, w);
    return sz[v];
}

int m = 0;
multiset<int> d[100500];
int cnt[100500];
int total[100500];

void dfs2(int v, int dep, int p)
{
    d[m].insert(dep);
    for (auto [i, w] : g[v])
        if (i!=p)
            dfs2(i, dep+w, v);
}

/*
7
1 3 99
2 3 82
3 4 4
4 5 43
5 6 5
4 7 3
 */

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    cin>>n;
    int SW = 0;
    for (int i=1; i<n; i++) {
        int x, y, w;
        cin>>x>>y>>w;
        SW += w;
        g[x].pb({y, w});
        g[y].pb({x, w});
    }

    dfs1(1, -1, 0);
    int C = 1;
    int P = -1;
    while (true)
    {
        bool ok = false;
        for (auto [i, w] : g[C])
            if (i!=P)
            if (2*sz[i] >= SW)
            {
                P = C;
                C = i;
                ok = true;
                break;
            }
        if (!ok)
            break;
    }
    m++;
    d[m] = {0};
    for (auto [i, w] : g[C])
    {
        m++;
        dfs2(i, w, C);
    }
    set<pair<int, int> > ms;
    for (int i=1; i<=m; i++)
    {
        ms.insert({*prev(d[i].end()), i});
        cnt[i] = 0;
    }
    int ans = 0;
    for (int id=1; id<=n/2; id++)
    {
        auto [w, i] = *prev(ms.end());
        ms.erase({w, i});
        ans += w;
        d[i].erase(d[i].find(w));
        if (d[i].size() > 0)
            ms.insert({*prev(d[i].end()), i});
        cnt[i]++;

        tie(w, i) = *prev(ms.end());
        if (cnt[i] < id)
        {
            ms.erase({w, i});
            ans += w;
            d[i].erase(d[i].find(w));
            if (d[i].size() > 0)
                ms.insert({*prev(d[i].end()), i});
            cnt[i]++;
        }
        else
        {
            tie(w, i) = *prev(prev(ms.end()));
            ms.erase({w, i});
            ans += w;
            d[i].erase(d[i].find(w));
            if (d[i].size() > 0)
                ms.insert({*prev(d[i].end()), i});
            cnt[i]++;
        }
        cout<<ans<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9720kb

input:

7
1 3 99
2 3 82
3 4 4
4 5 43
5 6 5
4 7 3

output:

181
280
287

result:

ok 3 number(s): "181 280 287"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 9868kb

input:

1000
328 12 58771429
881 504 17030494
847 622 20805817
12 922 58532669
879 929 52585738
495 726 27873950
855 17 37971674
797 941 76999719
702 610 719916
479 127 97829887
731 557 55300256
282 615 88802280
651 318 64099880
540 51 6547869
896 54 87823596
674 879 80674008
77 691 54802376
193 851 7869172...

output:

48829042195
97562386542
146216474947
194713456438
243120633399
291394542517
339657517459
387785045812
435787622310
483691355869
531476208289
579153483709
626793764008
674259794140
721617453738
768862531418
816032104456
863044440224
909960999950
956790589086
1003491332151
1050093110804
1096582356539
...

result:

wrong answer 490th numbers differ - expected: '12216146653570', found: '12217131911554'