Submission #678440

# Submission time Handle Problem Language Result Execution time Memory
678440 2023-01-06T02:39:15 Z DP_196 Relay Marathon (NOI20_relaymarathon) C++14
17 / 100
173 ms 2632 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define MASK(i) ((1LL) << (i))
#define all(x) x.begin(), x.end()
#define BIT(x, i) ((x) >> (i) & (1LL))
#define dbg(...) cerr << "#" << __LINE__ << ":[" << #__VA_ARGS__ \
<< "] = [" ,DBG(__VA_ARGS__)

string to_string(const string& s) { return '"' + s + '"'; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
        cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...);
}

template <class T>
inline bool maximize(T &a, const T &b) { return (a < b ? (a = b) : 0); }
template <class T>
inline bool minimize(T &a, const T &b) { return (a > b ? (a = b) : 0); }

const int MAXN = 1e5 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, m, k, a[505], cost[505][505];

struct dat {
	int v1 = INF, id1 = 0, v2 = INF, id2 = 0;
	dat (int _v1 = INF, int _id1 = 0, int _v2 = INF, int _id2 = 0) {
		v1 = _v1, id1 = _id1, v2 = _v2, id2 = _id2;
	} 
};

dat best[505];

void solve() {
	cin >> n >> m >> k;
	
	if (n > 500) return;
	
	memset(cost, 0x3f, sizeof (cost));
	
	for (int i = 1; i <= m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		minimize(cost[u][v], w);
		minimize(cost[v][u], w);
	}
	
	for (int i = 1; i <= k; i++) cin >> a[i];
	
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				minimize(cost[i][j], cost[i][k] + cost[k][j]);

	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			if (i == j) continue;
			int u = a[i], v = a[j];
			
			if (best[u].v1 >= cost[u][v]) {
				best[u] = dat(cost[u][v], v, best[u].v1, best[u].id1);
			}
			else if (cost[u][v] < best[u].v2) {
				best[u].v2 = cost[u][v];
				best[u].id2 = v;
			}
		}
	}
	
	int res = INF;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			if (i == j) continue;
			int u = a[i], v = a[j], sum = INF;
			if (best[u].id1 != v && best[u].id1 != best[v].id1 && best[v].id1 != u) {
				minimize(sum, best[u].v1 + best[v].v1);
			}
			
			if (best[u].id1 != v && best[u].id1 != best[v].id2 && best[v].id2 != u) {
				minimize(sum, best[u].v1 + best[v].v2);
			}
			
			if (best[u].id2 != v && best[u].id2 != best[v].id1 && best[v].id1 != u) {
				minimize(sum, best[u].v2 + best[v].v1);
			}
			
			if (best[u].id2 != v && best[u].id2 != best[v].id2 && best[v].id2 != u) {
				minimize(sum, best[u].v2 + best[v].v2);
			}
			
			minimize(res, sum);
		}
	}
	
	cout << res;
}

#define TASK "4SPECIAL"
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    int ntest = 1;
    //cin >> ntest;
    while (ntest--) solve();

    return 0;
}
//612
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1248 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 1248 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 2 ms 1352 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1232 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1248 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 1248 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 2 ms 1352 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1232 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 88 ms 1236 KB Output is correct
32 Correct 139 ms 1316 KB Output is correct
33 Correct 106 ms 1248 KB Output is correct
34 Correct 86 ms 1316 KB Output is correct
35 Correct 88 ms 1316 KB Output is correct
36 Correct 115 ms 1484 KB Output is correct
37 Correct 119 ms 1388 KB Output is correct
38 Correct 105 ms 1236 KB Output is correct
39 Correct 126 ms 2276 KB Output is correct
40 Correct 119 ms 1508 KB Output is correct
41 Correct 96 ms 1236 KB Output is correct
42 Correct 126 ms 1516 KB Output is correct
43 Correct 106 ms 1364 KB Output is correct
44 Correct 98 ms 1240 KB Output is correct
45 Correct 87 ms 1236 KB Output is correct
46 Correct 148 ms 2508 KB Output is correct
47 Correct 115 ms 1456 KB Output is correct
48 Correct 132 ms 2084 KB Output is correct
49 Correct 128 ms 2260 KB Output is correct
50 Correct 103 ms 1324 KB Output is correct
51 Correct 99 ms 1320 KB Output is correct
52 Correct 94 ms 1328 KB Output is correct
53 Correct 131 ms 1844 KB Output is correct
54 Correct 173 ms 2332 KB Output is correct
55 Correct 92 ms 1236 KB Output is correct
56 Correct 92 ms 1236 KB Output is correct
57 Correct 95 ms 1328 KB Output is correct
58 Correct 140 ms 2632 KB Output is correct
59 Correct 98 ms 1328 KB Output is correct
60 Correct 109 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1248 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 1248 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 2 ms 1352 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1232 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 88 ms 1236 KB Output is correct
32 Correct 139 ms 1316 KB Output is correct
33 Correct 106 ms 1248 KB Output is correct
34 Correct 86 ms 1316 KB Output is correct
35 Correct 88 ms 1316 KB Output is correct
36 Correct 115 ms 1484 KB Output is correct
37 Correct 119 ms 1388 KB Output is correct
38 Correct 105 ms 1236 KB Output is correct
39 Correct 126 ms 2276 KB Output is correct
40 Correct 119 ms 1508 KB Output is correct
41 Correct 96 ms 1236 KB Output is correct
42 Correct 126 ms 1516 KB Output is correct
43 Correct 106 ms 1364 KB Output is correct
44 Correct 98 ms 1240 KB Output is correct
45 Correct 87 ms 1236 KB Output is correct
46 Correct 148 ms 2508 KB Output is correct
47 Correct 115 ms 1456 KB Output is correct
48 Correct 132 ms 2084 KB Output is correct
49 Correct 128 ms 2260 KB Output is correct
50 Correct 103 ms 1324 KB Output is correct
51 Correct 99 ms 1320 KB Output is correct
52 Correct 94 ms 1328 KB Output is correct
53 Correct 131 ms 1844 KB Output is correct
54 Correct 173 ms 2332 KB Output is correct
55 Correct 92 ms 1236 KB Output is correct
56 Correct 92 ms 1236 KB Output is correct
57 Correct 95 ms 1328 KB Output is correct
58 Correct 140 ms 2632 KB Output is correct
59 Correct 98 ms 1328 KB Output is correct
60 Correct 109 ms 1236 KB Output is correct
61 Incorrect 1 ms 340 KB Output isn't correct
62 Halted 0 ms 0 KB -