28192023-01-26 13:54:06bzsofiaÚtadócpp11Hibás válasz 25/50114ms16396 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=0;
    int ag = 1;
    vector <int> sz;
};

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

struct adat3
{
    int cost, poz;
    pair <int, int> elek;
};

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(adat3 a, adat3 b)
{
    return a.cost<b.cost;
}

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

bool comp3(adat3 a, adat3 b)
{
    return a.poz < b.poz;
}

int main()
{
    cin >> n;
    vector <adat2> el(n);
    vector <adat3> 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].cost;
        ar[i].poz = i;
    }

    mely(1);

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

    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(), comp2);

    for (i = 1; i < n; ++i)
    {
        sum = (sum + (el[i].db * ar[i].cost)) % mod;
        ar[i].elek = { el[i].par.first, el[i].par.second };
    }

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

    cout << sum<<"\n";
    for (i = 1; i < n; ++i)
    {
        cout << ar[i].elek.first << " " << ar[i].elek.second << " " << ar[i].cost << "\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ÖsszpontTesztVerdiktIdőMemória
base25/50
1Elfogadva0/03ms1816 KiB
2Hibás válasz0/041ms5476 KiB
3Részben helyes1/22ms2220 KiB
4Részben helyes1/22ms2452 KiB
5Részben helyes1/22ms2692 KiB
6Részben helyes1/22ms2764 KiB
7Részben helyes1/22ms2860 KiB
8Részben helyes4/8108ms16396 KiB
9Részben helyes1/24ms3280 KiB
10Részben helyes1/24ms3300 KiB
11Részben helyes1/24ms3284 KiB
12Részben helyes1/24ms3264 KiB
13Részben helyes1/24ms3652 KiB
14Részben helyes1/2105ms12396 KiB
15Részben helyes1/2104ms12272 KiB
16Részben helyes1/2104ms12272 KiB
17Részben helyes1/2104ms12328 KiB
18Részben helyes1/2104ms12544 KiB
19Részben helyes1/2104ms12732 KiB
20Részben helyes1/2105ms12808 KiB
21Részben helyes1/2105ms13004 KiB
22Részben helyes1/2107ms12876 KiB
23Részben helyes1/2109ms12880 KiB
24Részben helyes1/2114ms13132 KiB