2810 2023. 01. 26 13:34:13 bzsofia Útadó cpp11 Hibás válasz 25/50 104ms 15512 KiB
// Utado.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

struct adat
{
    bool lat;
    int ag = 1;
    vector <int> sz;
};

struct adat2
{
    int db;
    pair<int, int> par;
};

int i, n, a, b, mod=32609;
long long sum;
vector <adat> x;

void mely(int akt)
{
    x[akt].lat = 1;
    for (auto& e : x[akt].sz)
    {
        if (!x[e].lat)
        {
            mely(e);
            x[akt].ag += x[e].ag;
        }
    }
}

bool comp(adat2 a, adat2 b)
{
    return a.db < b.db;
}

int main()
{
    cin >> n;
    vector <adat2> el(n);
    vector <int> ar(n);
    x.resize(n + 1);

    for (i = 1; i < n; ++i)
    {
        cin >> a >> b;

        el[i].par = { a, b };
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }

    for (i = 1; i < n; ++i)
    {
        cin >> ar[i];
    }

    mely(1);

    sort(ar.begin() + 1, ar.end());

    for (i = 1; i < n; ++i)
    {
        b = el[i].par.second;
        el[i].db = 2 * x[b].ag * (n - x[b].ag);
        //cout << el[i].par.first << " " << el[i].par.second << " " << el[i].db << "\n";
    }

    sort(el.begin() + 1, el.end(), comp);

    for (i = 1; i < n; ++i)
    {
        sum = (sum + (el[i].db * ar[i])) % mod;
    }

    cout << sum%mod<<"\n";
    for (i = 1; i < n; ++i)
    {
        cout << el[i].par.first << " " << el[i].par.second << " " << ar[i] << "\n";
    }

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 25/50
1 Elfogadva 0/0 3ms 1808 KiB
2 Hibás válasz 0/0 39ms 5100 KiB
3 Részben helyes 1/2 2ms 2548 KiB
4 Részben helyes 1/2 2ms 2556 KiB
5 Részben helyes 1/2 2ms 2692 KiB
6 Részben helyes 1/2 2ms 3020 KiB
7 Részben helyes 1/2 2ms 3112 KiB
8 Részben helyes 4/8 100ms 15512 KiB
9 Részben helyes 1/2 4ms 3256 KiB
10 Részben helyes 1/2 4ms 3200 KiB
11 Részben helyes 1/2 4ms 3196 KiB
12 Részben helyes 1/2 4ms 3524 KiB
13 Részben helyes 1/2 4ms 3808 KiB
14 Részben helyes 1/2 101ms 11112 KiB
15 Részben helyes 1/2 96ms 11340 KiB
16 Részben helyes 1/2 96ms 11372 KiB
17 Részben helyes 1/2 103ms 11564 KiB
18 Részben helyes 1/2 104ms 11568 KiB
19 Részben helyes 1/2 98ms 11696 KiB
20 Részben helyes 1/2 100ms 11644 KiB
21 Részben helyes 1/2 97ms 11756 KiB
22 Részben helyes 1/2 104ms 11748 KiB
23 Részben helyes 1/2 97ms 11752 KiB
24 Részben helyes 1/2 98ms 11776 KiB