QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218876#7144. CandiesSolitaryDream#WA 1ms3896kbC++172.4kb2023-10-18 19:46:272023-10-18 19:46:28

Judging History

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

  • [2023-10-18 19:46:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3896kb
  • [2023-10-18 19:46:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 2010;
const int M = 16;
int n, nn;
int ans[N][M];
set<pii> g[N];
inline void Build(const vector<pii> &a, int fa, int l, int r) {
    if (l == r) {
        g[a[l].first].insert({fa, a[l].second});
        g[fa].insert(a[l]);
        return;
    }
    int mid = (l + r) >> 1;
    int cur = ++nn;
    Build(a, cur, l, mid);
    Build(a, cur, mid + 1, r);
    g[fa].insert({cur, 0});
    g[cur].insert({fa, 0});
}
int del[N], si[N], mxsi, mxu, mxv;
inline void GetSi(int x, int fa) {
    si[x] = 1;
    for (auto [y, z] : g[x]) if (y != fa && !del[y]) {
        GetSi(y, x);
        si[x] += si[y];
    }
}
inline void GetUV(int x, int fa, int all) {
    int cursi = max(all - si[x], si[x]);
    if (cursi < mxsi) mxsi = cursi, mxu = x, mxv = fa;
    for (auto [y, z] : g[x]) if (y != fa && !del[y]) {
        GetUV(y, x, all);
    }
}
inline void Paint(int x, int fa, int de, int q, int dis) {
    ans[x][de] = dis;
    for (auto [y, z] : g[x]) if (y != fa && !del[y]) {
        Paint(y, x, de, q, dis + q * z);
    }
}
inline void PaintAdd(int x, int fa, int de, int add, int minus) {
    for (int i = de; i < M; ++i) {
        ans[x][i] += ans[add][i] - ans[minus][i];
    }
    for (auto [y, z] : g[x]) if (y != fa && !del[y]) {
        PaintAdd(y, x, de, add, minus);
    }
}
inline void Solve(int x, int de) {
    GetSi(x, 0);
    if (si[x] == 1) return;
    mxsi = 1e9;
    GetUV(x, 0, si[x]);
    int u = mxu, v = mxv;
    printf("cut %d %d\n", u, v);
    Paint(u, v, de, -1, 0);
    Paint(v, u, de, 1, g[u].lower_bound({v, 0})->second);
    del[u] = 1; Solve(v, de + 1); del[u] = 0;
    del[v] = 1; Solve(u, de + 1); del[v] = 0;
    PaintAdd(v, u, de + 1, u, v);
}
int main() {
    scanf("%d", &n);
    nn = n;
    for (int i = 1, x, y, z; i < n; ++i) {
        scanf("%d%d%d", &x, &y, &z);
        g[x].insert({y, z});
        g[y].insert({x, z});
    }
    for (int i = 1; i <= n; ++i) if (g[i].size() > 3) {
        vector<pii> tmp(g[i].begin(), g[i].end());
        for (auto [y, z] : g[i]) g[y].erase({i, z});
        g[i].clear();
        Build(tmp, i, 0, tmp.size() - 1);
    }
    Solve(1, 0);
    printf("%d\n", M);
    for (int i = 1; i <= n; puts(""), ++i)
        for (int j = 0; j < M; ++j) 
            printf("%d ", ans[i][j]);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3896kb

input:

2 1 2 2
1 2

output:

cut 2 1
16
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong output format Expected integer, but "cut" found