74812024-01-09 10:15:10GhostTársaság (50)cpp17Wrong answer 0/5010ms4064 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <limits.h>

using namespace std;

int main()
{
    int n, k, i, temp1, temp2, max = 0;
    cin >> n >> k;

    vector<vector<pair<int, int>>> connections(n);
    for (i = 1; i < n; i++) {
        cin >> temp1 >> temp2;
        temp1--;
        connections[temp1].push_back({ i,temp2 });
    }

    queue<pair<int, int>> steps; // 0 current pos; 1 distance
    steps.push({ 0,0 });
    vector<int> distance(n, INT_MAX);
    while (steps.size() != 0) {
        int node = steps.front().first, dis = steps.front().second;
        steps.pop();
        if (dis < distance[node]) {
            distance[node] = dis;
        }
        if (max < dis) {
            max = dis;
        }
        for (i = 0; i < connections[node].size(); i++) {
            steps.push({ connections[node][i].first, dis + connections[node][i].second });
        }
    }
    for (i = 0; i < n; i++) {
        if (distance[i] == max) {
            cout << i+1;
            break;
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1816 KiB
2Wrong answer0/07ms2544 KiB
3Wrong answer0/33ms2132 KiB
4Wrong answer0/33ms2216 KiB
5Wrong answer0/33ms2304 KiB
6Wrong answer0/33ms2440 KiB
7Wrong answer0/33ms2668 KiB
8Wrong answer0/33ms2772 KiB
9Wrong answer0/34ms3072 KiB
10Wrong answer0/34ms3200 KiB
11Wrong answer0/34ms3248 KiB
12Wrong answer0/37ms3552 KiB
13Wrong answer0/48ms3540 KiB
14Wrong answer0/48ms3816 KiB
15Wrong answer0/48ms4012 KiB
16Wrong answer0/49ms4064 KiB
17Wrong answer0/410ms4064 KiB