93142024-02-20 12:39:57AblablablaÚtadócpp17Wrong answer 0/50104ms16768 KiB
#include <bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;

const ll MOD = 32609;

vector<vector<int>> csucsok;
vector<int> alatta;

int bejar(int akt, int elozo){
    for(int x : csucsok[akt]){
        if(x == elozo) continue;

        alatta[akt] += bejar(x, akt);
    }

    alatta[akt]++;
    return alatta[akt];
}

int main()
{
    int n;
    cin >> n;

    int m = n - 1;

    csucsok.assign(n, vector<int>());
    vector<pii> elek;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;

        csucsok[a].push_back(b);
        csucsok[b].push_back(a);
        elek.push_back({a, b});
    }

    alatta.assign(n, 0);
    bejar(0, -1);

    vector<int> adok(m);
    for(int i = 0; i < m; i++){
        cin >> adok[i];
        adok[i] %= MOD;
    }

    sort(adok.begin(), adok.end(), greater<int>());

    vector<pii> sor(m);
    for(int i = 0; i < m; i++){
        int a = alatta[elek[i].first];
        int b = alatta[elek[i].second];

        int lent, fent;

        if(a < b){
            lent = a;
            fent = n - a;
        } else{
            lent = b;
            fent = n - b;
        }

        sor[i] = {lent * fent, i};
    }

    ll valasz = 0;

    sort(sor.begin(), sor.end(), greater<pii>());
    for(int i = 0; i < m; i++){
        valasz += sor[i].first * adok[i];
        valasz %= MOD;
    }

    cout << (valasz * 2) % MOD << "\n";

    for(int i = 0; i < m; i++){
        cout << elek[sor[i].second].first + 1 << " " << elek[sor[i].second].second + 1 << " " << adok[i] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1812 KiB
2Wrong answer0/039ms5496 KiB
3Wrong answer0/23ms2680 KiB
4Wrong answer0/23ms2856 KiB
5Wrong answer0/23ms3068 KiB
6Wrong answer0/23ms3156 KiB
7Wrong answer0/23ms3292 KiB
8Wrong answer0/897ms16768 KiB
9Wrong answer0/24ms4752 KiB
10Wrong answer0/24ms4728 KiB
11Wrong answer0/24ms4744 KiB
12Wrong answer0/24ms4764 KiB
13Wrong answer0/24ms4788 KiB
14Wrong answer0/298ms13556 KiB
15Wrong answer0/2104ms14672 KiB
16Wrong answer0/298ms15668 KiB
17Wrong answer0/297ms15764 KiB
18Wrong answer0/297ms15900 KiB
19Wrong answer0/297ms15936 KiB
20Wrong answer0/298ms16068 KiB
21Wrong answer0/298ms16284 KiB
22Wrong answer0/2100ms16288 KiB
23Wrong answer0/298ms16248 KiB
24Wrong answer0/2101ms16244 KiB