46622023-03-30 18:33:25ZsofiaKeresztelyÚtadócpp14Wrong answer 25/5098ms19168 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll MOD = 32609;
#define fi first
#define se second
vector<vector<int> > g;
vector<int> p;
vector<pair<ll, int> > times;
ll n;

ll mul(ll a, ll b){
    a %= MOD;
    b %= MOD;
    return a * b % MOD;
}

int dfs(int v){
    ll r = 1;
    for (int x : g[v]){
        if (x == p[v]) continue;
        p[x] = v;
        r += dfs(x);
    }
    times[v].se = v;
    times[v].fi = r * 2 * (n - r);
    return r;
}

int main()
{
    cin >> n;
    g.resize(n+1);
    p.resize(n+1);
    times.resize(n+1);
    for (int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    p[1] = 0;
    dfs(1);
    vector<ll> w(n+1, 0);
    for (int i=2; i<=n; i++){
        cin >> w[i];
    }
    sort(w.begin(), w.end());
    sort(times.begin(), times.end());
    ll op = 0;
    for (int i=2; i<=n; i++){
        op += mul(w[i], times[i].fi);
    }
    cout << op << "\n";
    for (int i=2; i<=n; i++){
        cout << times[i].se << " " << p[times[i].se] << " " << w[i] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1820 KiB
2Wrong answer0/039ms5140 KiB
3Partially correct1/23ms2224 KiB
4Partially correct1/23ms2436 KiB
5Partially correct1/23ms2644 KiB
6Partially correct1/23ms2860 KiB
7Partially correct1/23ms3068 KiB
8Partially correct4/898ms19168 KiB
9Partially correct1/24ms3484 KiB
10Partially correct1/24ms3516 KiB
11Partially correct1/24ms3776 KiB
12Partially correct1/24ms3728 KiB
13Partially correct1/24ms3952 KiB
14Partially correct1/297ms12216 KiB
15Partially correct1/297ms12436 KiB
16Partially correct1/297ms12312 KiB
17Partially correct1/297ms12568 KiB
18Partially correct1/297ms12528 KiB
19Partially correct1/298ms12720 KiB
20Partially correct1/297ms12816 KiB
21Partially correct1/298ms12800 KiB
22Partially correct1/297ms12716 KiB
23Partially correct1/297ms12972 KiB
24Partially correct1/297ms13156 KiB