15982022-11-28 20:33:34kicsiboglarLogisztikai központcpp11Wrong answer 1/50151ms25724 KiB
#include <iostream>
#include <vector>
#include <deque>
#define ll long long 

using namespace std;

struct element
{
    bool seen = false;
    vector <pair<ll, ll> > sz;
    ll step, dis, from;
};
ll n, a, b, c, i, j, start;
vector <element> x;

void bfs(ll act)
{
    deque<ll> v;
    v.push_back(act);
    x[act].seen = true;
    ll curr;
    while (!v.empty())
    {
        curr = v[0];
        v.pop_front();
        for (auto& e : x[curr].sz)
        {
            if (!x[e.first].seen)
            {
                x[e.first].dis = x[curr].dis + e.second;
                x[e.first].from = curr;
                x[e.first].seen = true;
                x[e.first].step = x[curr].step + 1;
                v.push_back(e.first);
            }
        }
    }
}
int main()
{
    cin >> n;
    x.resize(n + 1);
    for (i = 1; i < n; ++i)
    {
        cin >> a >> b >> c;
        x[a].sz.push_back({ b,c });
        x[b].sz.push_back({ a,c });
    }


    bfs(1);
    ll maxi = 0;
    for (i = 1; i <= n; ++i)
    {
        if (x[i].dis > maxi)
        {
            maxi = x[i].dis;
            start = i;
        }
        x[i].seen = false;
        x[i].dis = 0;
        x[i].step = 0;
    }


    bfs(start);
    ll pos = 0;
    maxi = 0;
    for (i = 1; i <= n; ++i)
    {
        if (x[i].dis > maxi)
        {
            maxi = x[i].dis;
            pos = i;
        }
        x[i].seen = false;
      
    }



    ll middle = x[pos].dis / 2,pos2=pos;

    while (x[pos2].dis>middle)
    {
        pos2 = x[pos2].from;
    }

    cout << pos2;
    /*
    maxi = max(x[pos].dis - x[pos2].dis, x[pos2].dis);



    ll maxii = 999999;
    ll o = 0;
    if (x[pos].step % 2 != 0)
    {
        o = x[pos2].from;
        maxii = max(x[pos].dis - x[o].dis, x[o].dis);
    }
    cout << min(maxi, maxii)<<"\n";
    if (maxi == maxii)
    {
        cout << "2\n";
        cout << maxi << " " << maxii;
    }
    else
    {
        cout << "1\n";
        if (maxi < maxii) cout << pos2;
        else cout << o;
    }*/
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Wrong answer0/03ms1680 KiB
2Wrong answer0/0126ms21008 KiB
3Wrong answer0/42ms2056 KiB
4Wrong answer0/42ms2288 KiB
5Wrong answer0/42ms2336 KiB
6Wrong answer0/42ms2448 KiB
7Wrong answer0/42ms2472 KiB
8Wrong answer0/53ms2896 KiB
9Wrong answer0/2151ms24192 KiB
10Wrong answer0/2144ms24540 KiB
11Wrong answer0/23ms3448 KiB
12Partially correct1/23ms3604 KiB
13Wrong answer0/28ms4276 KiB
14Wrong answer0/214ms5296 KiB
15Wrong answer0/2137ms22836 KiB
16Wrong answer0/2127ms22144 KiB
17Wrong answer0/2142ms23648 KiB
18Wrong answer0/2105ms18848 KiB
19Wrong answer0/2145ms25724 KiB
20Wrong answer0/3143ms25212 KiB