Submission #67943870


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
void solve();
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) solve();
    return 0;
}
ll dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
void solve() {
    ll n, m;
    cin >> n >> m;
    constexpr ll INF = 1e18;
    vector<vector<ll>> dist(n + 1, vector<ll>(n + 1, INF));
    for (ll i = 0; i < n + 1; i++) dist[i][i] = 0;
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }
    ll k, T;
    cin >> k >> T;
    set<ll> st;
    vector<ll> d(k);
    rep(i, k) {
        cin >> d[i];
        d[i]--;
        st.insert(d[i]);
        dist[d[i]][n] = 0;
        dist[n][d[i]] = T;
    }
    rep(k, n + 1) rep(i, n + 1) rep(j, n + 1) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    ll res = 0;
    rep(i, n) rep(j, n) {
        if (dist[i][j] == INF) continue;
        res += dist[i][j];
    }
    ll q;
    cin >> q;
    auto update = [&](ll a, ll b, ll c) {
        if (dist[a][b] > c) {
            if (a != n and b != n) {
                if (dist[a][b] != INF) res -= dist[a][b];
                res += c;
            }
            dist[a][b] = c;
        }
    };
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll a, b, c;
            cin >> a >> b >> c;
            a--, b--;
            if (dist[a][b] <= c) continue;
            rep(i, n + 1) rep(j, n + 1) {
                update(i, j, dist[i][a] + c + dist[b][j]);
                update(i, j, dist[i][b] + c + dist[a][j]);
            }
        } else if (t == 2) {
            ll x;
            cin >> x;
            x--;
            if (st.count(x)) continue;
            st.insert(x);
            rep(i, n + 1) rep(j, n + 1) {
                update(i, j, dist[i][x] + dist[n][j]);
                update(i, j, dist[i][n] + T + dist[x][j]);
            }
        } else {
            cout << res << "\n";
        }
    }
}

Submission Info

Submission Time
Task E - Development
User littlegirl112
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2544 Byte
Status AC
Exec Time 329 ms
Memory 5524 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 1 ms 3408 KiB
random_01.txt AC 304 ms 5200 KiB
random_02.txt AC 65 ms 4128 KiB
random_03.txt AC 257 ms 5464 KiB
random_04.txt AC 195 ms 4952 KiB
random_05.txt AC 297 ms 5200 KiB
random_06.txt AC 70 ms 3788 KiB
random_07.txt AC 235 ms 5456 KiB
random_08.txt AC 221 ms 5336 KiB
random_09.txt AC 276 ms 5516 KiB
random_10.txt AC 69 ms 4152 KiB
random_11.txt AC 210 ms 5380 KiB
random_12.txt AC 95 ms 4596 KiB
random_13.txt AC 205 ms 5192 KiB
random_14.txt AC 43 ms 3900 KiB
random_15.txt AC 203 ms 5488 KiB
random_16.txt AC 101 ms 4692 KiB
random_17.txt AC 183 ms 5524 KiB
random_18.txt AC 122 ms 4872 KiB
random_19.txt AC 192 ms 5444 KiB
random_20.txt AC 133 ms 5004 KiB
random_21.txt AC 35 ms 3792 KiB
random_22.txt AC 102 ms 4288 KiB
random_23.txt AC 77 ms 4556 KiB
random_24.txt AC 95 ms 4512 KiB
random_25.txt AC 284 ms 5172 KiB
random_26.txt AC 130 ms 5192 KiB
random_27.txt AC 329 ms 5248 KiB
sample_01.txt AC 1 ms 3468 KiB