QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179283#6888. TeyvatPPP#ML 0ms0kbC++171.7kb2023-09-14 20:15:062023-09-14 20:15:07

Judging History

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

  • [2023-09-14 20:15:07]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-09-14 20:15:06]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 200500, mod = 998244353;

int n, a[N], b[N], ans[N];
vector<pair<int, pair<int, int> > > g[N];
int sz[N];

void dfs1(int v, int p) {
    sz[v] = 1;
    for (auto it: g[v]) {
        int to = it.first;
        if (to == p)
            continue;
        dfs1(to, v);
        sz[v] += sz[to];
    }
}

void dfs2(int v, int p, int k) {
    int u = -1;
    for (auto it: g[v]) {
        int to = it.first;
        if (to == p)
            continue;
        if (u == -1 || sz[to] > sz[u])
            u = to;
    }
    if (u != -1)
        dfs2(u, v, k - 1);
    for (auto it: g[v]) {
        int to = it.first;
        if (to == p || to == u)
            continue;
        dfs2(to, v, k + 1);
    }
}



void solve() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        g[i].clear();
    }

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b + n);
    for (int i = 0; i < n; i++)
        a[i] = lower_bound(b, b + n, a[i]) - b;

    for (int i = 0; i < n - 1; i++) {
        int v, u, w;
        cin >> v >> u >> w;
        v--, u--, w--;
        g[v].push_back({u, {w, i}});
        g[u].push_back({v, {w, i}});
    }
    dfs1(0, 0);
    dfs2(0, 0, 0);
    for (int i = 0; i < n - 1; i++)
        cout << ans[i] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--)
        solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

1000
92 95 16
76 55
19 12
57 7
39 90
38 89
48 60
29 67
35 52
32 83
10 80
64 11
66 63
90 57
17 70
20 42
31 87
91 41
33 72
12 14
9 38
30 82
72 21
9 81
40 9
73 60
71 82
48 69
70 26
72 34
25 62
10 75
83 92
16 18
34 79
15 72
65 13
64 12
37 63
46 16
32 1
23 78
22 18
78 68
49 78
48 13
39 72
39 44
27 25
20 ...

output:


result: