Submission #67944705


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

const long long inf = 1e18+3;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<long long>> adjm(n+1, vector<long long>(n+1, inf));
	for (int i=0; i<m; i++) {
		int a, b; long long c;
		cin >> a >> b >> c;
		a--; b--;
		long long mn = min(adjm[a][b], c);
		adjm[a][b] = adjm[b][a] = mn;
	}
	int c; long long t;
	cin >> c >> t;
	for (int i=0; i<c; i++) {
		int u;
		cin >> u;
		adjm[u-1][n] = t;
		adjm[n][u-1] = 0;
	}

	vector<vector<long long>> dist(n+1, vector<long long>(n+1, inf));
	for (int i=0; i<=n; i++) {
		for (int j=0; j<=n; j++) {
			dist[i][j] = (i == j ? 0 : adjm[i][j]);
		}
	}
	for (int k=0; k<=n; k++) {
		for (int i=0; i<=n; i++) {
			for (int j=0; j<=n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	long long ans = 0;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			ans += (dist[i][j] == inf ? 0 : dist[i][j]);
		}
	}

	int q;
	cin >> q;
	while (q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int u, v; long long w;
			cin >> u >> v >> w;
			u--; v--;

			long long mn = min(adjm[u][v], w);
			adjm[u][v] = adjm[v][u] = mn;
			for (int i=0; i<=n; i++) {
				for (int j=0; j<=n; j++) {
					if (i < n && j < n) ans -= (dist[i][j] == inf ? 0 : dist[i][j]);
					dist[i][j] = min({
						dist[i][j],
						dist[i][u] + adjm[u][v] + dist[v][j],
						dist[i][v] + adjm[v][u] + dist[u][j]
					});
					if (i < n && j < n) ans += (dist[i][j] == inf ? 0 : dist[i][j]);
				}
			}

		} else if (type == 2) {
			int u;
			cin >> u;
			u--;
			adjm[u][n] = t;
			adjm[n][u] = 0;
			for (int i=0; i<=n; i++) {
				for (int j=0; j<=n; j++) {
					if (i < n && j < n) ans -= (dist[i][j] == inf ? 0 : dist[i][j]);
					dist[i][j] = min({
						dist[i][j],
						dist[i][u] + adjm[u][n] + dist[n][j],
						dist[i][n] + adjm[n][u] + dist[u][j]
					});
					if (i < n && j < n) ans += (dist[i][j] == inf ? 0 : dist[i][j]);
				}
			}
		} else {
			cout << ans << '\n';
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int tcs = 1;
	// cin >> tcs;
	while (tcs--) {
		solve();
	}
	return 0;
}

Submission Info

Submission Time
Task E - Development
User Wie
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2225 Byte
Status AC
Exec Time 450 ms
Memory 7080 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 3424 KiB
random_01.txt AC 447 ms 6952 KiB
random_02.txt AC 104 ms 4076 KiB
random_03.txt AC 442 ms 6952 KiB
random_04.txt AC 347 ms 6116 KiB
random_05.txt AC 447 ms 7036 KiB
random_06.txt AC 128 ms 4436 KiB
random_07.txt AC 446 ms 6996 KiB
random_08.txt AC 416 ms 6732 KiB
random_09.txt AC 447 ms 7040 KiB
random_10.txt AC 137 ms 4312 KiB
random_11.txt AC 450 ms 7000 KiB
random_12.txt AC 231 ms 5212 KiB
random_13.txt AC 442 ms 6908 KiB
random_14.txt AC 116 ms 4228 KiB
random_15.txt AC 442 ms 6972 KiB
random_16.txt AC 268 ms 5756 KiB
random_17.txt AC 449 ms 7080 KiB
random_18.txt AC 343 ms 6240 KiB
random_19.txt AC 443 ms 6980 KiB
random_20.txt AC 330 ms 6240 KiB
random_21.txt AC 30 ms 4628 KiB
random_22.txt AC 173 ms 4576 KiB
random_23.txt AC 237 ms 5216 KiB
random_24.txt AC 185 ms 4924 KiB
random_25.txt AC 410 ms 6992 KiB
random_26.txt AC 405 ms 6972 KiB
random_27.txt AC 445 ms 7008 KiB
sample_01.txt AC 1 ms 3468 KiB