Submission #67981215


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll INF = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M;
    cin >> N >> M;
    
    ll dp[501][501];
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            dp[i][j] = INF;
        }
        dp[i][i] = 0;
    }
    
    for (int i = 1; i <= M; i++) {
        int A, B; ll C;
        cin >> A >> B >> C;
        dp[A][B] = dp[B][A] = min(dp[A][B], 2*C);
    }
    
    int K; ll T;
    cin >> K >> T;
    for (int i = 1; i <= K; i++) {
        int D;
        cin >> D;
        dp[0][D] = dp[D][0] = T;
    }
    
    for (int k = 0; k <= N; k++)
        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= N; j++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                
    auto update_edge = [&dp, N](int A, int B, ll C) {
        dp[A][B] = dp[B][A] = min(dp[A][B], C);
        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= N; j++)
                dp[i][j] = min({dp[i][j], dp[i][A] + dp[A][B] + dp[B][j], dp[i][B] + dp[B][A] + dp[A][j]});
    };
    
    int Q;
    cin >> Q;
    while (Q--) {
        int cmd;
        cin >> cmd;
        if (cmd == 1) {
            int A, B; ll C;
            cin >> A >> B >> C;
            update_edge(A, B, 2*C);
        } else if (cmd == 2) {
            int D;
            cin >> D;
            update_edge(0, D, T);
        } else {
            ll sum = 0;
            for (int i = 1; i <= N; i++)
                for (int j = 1; j <= N; j++)
                    sum += (dp[i][j] < INF) * dp[i][j];
            cout << sum/2 << "\n";
        }
    }
    return 0;
}

Submission Info

Submission Time
Task E - Development
User omsincoconut
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1783 Byte
Status AC
Exec Time 317 ms
Memory 5556 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 1
AC × 29
Set Name Test Cases
Sample sample_01.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, sample_01.txt
Case Name Status Exec Time Memory
hand.txt AC 2 ms 5404 KiB
random_01.txt AC 317 ms 5488 KiB
random_02.txt AC 70 ms 5436 KiB
random_03.txt AC 313 ms 5416 KiB
random_04.txt AC 246 ms 5556 KiB
random_05.txt AC 317 ms 5412 KiB
random_06.txt AC 88 ms 5452 KiB
random_07.txt AC 313 ms 5452 KiB
random_08.txt AC 294 ms 5440 KiB
random_09.txt AC 316 ms 5348 KiB
random_10.txt AC 92 ms 5500 KiB
random_11.txt AC 316 ms 5308 KiB
random_12.txt AC 162 ms 5332 KiB
random_13.txt AC 316 ms 5556 KiB
random_14.txt AC 79 ms 5352 KiB
random_15.txt AC 313 ms 5496 KiB
random_16.txt AC 193 ms 5440 KiB
random_17.txt AC 316 ms 5424 KiB
random_18.txt AC 241 ms 5496 KiB
random_19.txt AC 314 ms 5408 KiB
random_20.txt AC 233 ms 5444 KiB
random_21.txt AC 97 ms 5376 KiB
random_22.txt AC 118 ms 5448 KiB
random_23.txt AC 172 ms 5492 KiB
random_24.txt AC 130 ms 5444 KiB
random_25.txt AC 310 ms 5376 KiB
random_26.txt AC 307 ms 5496 KiB
random_27.txt AC 317 ms 5380 KiB
sample_01.txt AC 2 ms 5316 KiB