CODE FESTIVAL 2016 Relay (Parallel)

Submission #1351541

Source codeソースコード

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int, int>>X[1 << 17], Y[1 << 17]; int dist[1 << 17], N, A, B, C, root; queue<int>Q;
int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) { cin >> A >> B >> C; X[A].push_back(make_pair(B, C)); Y[B].push_back(make_pair(A, C)); }
    for (int i = 0; i < N; i++) { if (Y[i].size() == 0) { root = i; } }
    for (int i = 0; i < N; i++) { dist[i] = 1145141919; }Q.push(root); dist[root] = 0;
    while (!Q.empty()) {
        int a1 = Q.front(); Q.pop();
        for (int i = 0; i < X[a1].size(); i++) {
            int to = X[a1][i].first, a2 = X[a1][i].second;
            if (dist[to] == 1145141919) { dist[to] = dist[a1] + a2; Q.push(to); }
        }
    }
    int maxn = 0, maxid = 0;
    for (int i = 0; i < N; i++) { if (maxn < dist[i]) { maxn = dist[i]; maxid = i; } }Q.push(maxid);
    for (int i = 0; i < N; i++) { dist[i] = 1145141919; }dist[maxid] = 0;
    while (!Q.empty()) {
        int a1 = Q.front(); Q.pop(); maxn = 0; maxid = 0;
        for (int i = 0; i < X[a1].size(); i++) {
            int to = X[a1][i].first, a2 = X[a1][i].second;
            if (dist[to] > dist[a1] + a2) { dist[to] = dist[a1] + a2; Q.push(to); }
        }
        for (int i = 0; i < Y[a1].size(); i++) {
            int to = Y[a1][i].first, a2 = Y[a1][i].second;
            if (dist[to] > dist[a1] + a2) { dist[to] = dist[a1] + a2; Q.push(to); }
        }
    }
    for (int i = 0; i < N; i++) { if (maxn < dist[i]) { maxn = dist[i]; maxid = i; } }
    cout << maxn+1 << endl;
    return 0;
}

Submission

Task問題 K - 木の問題 / Problem on Tree
User nameユーザ名 E869120
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1610 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 0 / 100 sample_01.txt,sample_02.txt,sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask1_26.txt,subtask1_27.txt,subtask1_28.txt,subtask1_29.txt,subtask1_30.txt,subtask1_31.txt,subtask1_32.txt,subtask1_33.txt,subtask1_34.txt,subtask1_35.txt,subtask1_36.txt,subtask1_37.txt,subtask1_38.txt,subtask1_39.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt WA
sample_02.txt WA
subtask1_01.txt WA
subtask1_02.txt WA
subtask1_03.txt WA
subtask1_04.txt WA
subtask1_05.txt WA
subtask1_06.txt WA
subtask1_07.txt WA
subtask1_08.txt WA
subtask1_09.txt WA
subtask1_10.txt WA
subtask1_11.txt WA
subtask1_12.txt WA
subtask1_13.txt WA
subtask1_14.txt WA
subtask1_15.txt WA
subtask1_16.txt WA
subtask1_17.txt WA
subtask1_18.txt WA
subtask1_19.txt WA
subtask1_20.txt WA
subtask1_21.txt WA
subtask1_22.txt WA
subtask1_23.txt WA
subtask1_24.txt WA
subtask1_25.txt WA
subtask1_26.txt WA
subtask1_27.txt WA
subtask1_28.txt WA
subtask1_29.txt WA
subtask1_30.txt WA
subtask1_31.txt WA
subtask1_32.txt WA
subtask1_33.txt WA
subtask1_34.txt WA
subtask1_35.txt WA
subtask1_36.txt WA
subtask1_37.txt WA
subtask1_38.txt WA
subtask1_39.txt WA