답안 #379940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379940 2021-03-19T19:06:07 Z nikatamliani Relay Marathon (NOI20_relaymarathon) C++14
5 / 100
541 ms 5484 KB
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int a, int b) {
	return a + (unsigned long long)rng() % (b - a + 1);
}
const int oo = 1e9+10;
int calc(vector<int> &a, vector<int> &b, vector<vector<pair<int, int>>> &edges) {
	priority_queue<pair<int,int>> q;
	for(int x : a) {
		q.push({0, x});
	}
	vector<bool> fix(n), seen(n);
	for(int x : b) {
		fix[x] = 1;
	}
	while(!q.empty()) {
		pair<int,int> p = q.top(); q.pop();
		if(fix[p.second]) return -p.first;
		if(seen[p.second]) continue;
		seen[p.second] = 1;
		for(const pair<int,int> &to : edges[p.second]) {
			if(!seen[to.first]) {
				q.push({p.first - to.second, to.first});
			}
		}
	}
	return oo;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> k;
	vector<vector<pair<int, int>>> edges(n);
	for(int i = 0; i < m; ++i) {
		int u, v, w;
		cin >> u >> v >> w; --u, --v; 
		edges[u].push_back({v, w});
		edges[v].push_back({u, w});
	}
	vector<int> special(k);
	for(int &i : special) cin >> i, --i;
	int ans = oo;
	for(int it = 0; it * m < 1e6; ++it) {
		shuffle(special.begin(), special.end(), rng);
		vector<int> start[2], end[2];
		for(int i = 0; i < k / 2; ++i) {
			start[rand(0, 1)].push_back(special[i]);
		}
		for(int i = k / 2; i < k; ++i) {
			end[rand(0, 1)].push_back(special[i]);
		}
		ans = min(ans, calc(start[0], end[0], edges) + calc(start[1], end[1], edges));
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 364 KB Output is correct
2 Correct 37 ms 364 KB Output is correct
3 Correct 69 ms 364 KB Output is correct
4 Correct 541 ms 392 KB Output is correct
5 Correct 92 ms 492 KB Output is correct
6 Correct 68 ms 512 KB Output is correct
7 Correct 28 ms 364 KB Output is correct
8 Correct 33 ms 364 KB Output is correct
9 Correct 116 ms 364 KB Output is correct
10 Correct 132 ms 364 KB Output is correct
11 Correct 92 ms 364 KB Output is correct
12 Correct 83 ms 396 KB Output is correct
13 Correct 34 ms 364 KB Output is correct
14 Correct 38 ms 364 KB Output is correct
15 Correct 36 ms 364 KB Output is correct
16 Correct 69 ms 492 KB Output is correct
17 Correct 39 ms 364 KB Output is correct
18 Correct 63 ms 364 KB Output is correct
19 Correct 37 ms 364 KB Output is correct
20 Correct 37 ms 364 KB Output is correct
21 Correct 38 ms 364 KB Output is correct
22 Correct 128 ms 396 KB Output is correct
23 Correct 41 ms 364 KB Output is correct
24 Correct 77 ms 364 KB Output is correct
25 Correct 81 ms 364 KB Output is correct
26 Correct 63 ms 396 KB Output is correct
27 Correct 98 ms 492 KB Output is correct
28 Correct 34 ms 364 KB Output is correct
29 Correct 29 ms 364 KB Output is correct
30 Correct 31 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 364 KB Output is correct
2 Correct 37 ms 364 KB Output is correct
3 Correct 69 ms 364 KB Output is correct
4 Correct 541 ms 392 KB Output is correct
5 Correct 92 ms 492 KB Output is correct
6 Correct 68 ms 512 KB Output is correct
7 Correct 28 ms 364 KB Output is correct
8 Correct 33 ms 364 KB Output is correct
9 Correct 116 ms 364 KB Output is correct
10 Correct 132 ms 364 KB Output is correct
11 Correct 92 ms 364 KB Output is correct
12 Correct 83 ms 396 KB Output is correct
13 Correct 34 ms 364 KB Output is correct
14 Correct 38 ms 364 KB Output is correct
15 Correct 36 ms 364 KB Output is correct
16 Correct 69 ms 492 KB Output is correct
17 Correct 39 ms 364 KB Output is correct
18 Correct 63 ms 364 KB Output is correct
19 Correct 37 ms 364 KB Output is correct
20 Correct 37 ms 364 KB Output is correct
21 Correct 38 ms 364 KB Output is correct
22 Correct 128 ms 396 KB Output is correct
23 Correct 41 ms 364 KB Output is correct
24 Correct 77 ms 364 KB Output is correct
25 Correct 81 ms 364 KB Output is correct
26 Correct 63 ms 396 KB Output is correct
27 Correct 98 ms 492 KB Output is correct
28 Correct 34 ms 364 KB Output is correct
29 Correct 29 ms 364 KB Output is correct
30 Correct 31 ms 364 KB Output is correct
31 Correct 51 ms 364 KB Output is correct
32 Correct 68 ms 364 KB Output is correct
33 Correct 74 ms 364 KB Output is correct
34 Correct 23 ms 364 KB Output is correct
35 Correct 5 ms 364 KB Output is correct
36 Correct 27 ms 492 KB Output is correct
37 Correct 35 ms 620 KB Output is correct
38 Correct 44 ms 364 KB Output is correct
39 Incorrect 44 ms 3776 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 5484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 364 KB Output is correct
2 Correct 37 ms 364 KB Output is correct
3 Correct 69 ms 364 KB Output is correct
4 Correct 541 ms 392 KB Output is correct
5 Correct 92 ms 492 KB Output is correct
6 Correct 68 ms 512 KB Output is correct
7 Correct 28 ms 364 KB Output is correct
8 Correct 33 ms 364 KB Output is correct
9 Correct 116 ms 364 KB Output is correct
10 Correct 132 ms 364 KB Output is correct
11 Correct 92 ms 364 KB Output is correct
12 Correct 83 ms 396 KB Output is correct
13 Correct 34 ms 364 KB Output is correct
14 Correct 38 ms 364 KB Output is correct
15 Correct 36 ms 364 KB Output is correct
16 Correct 69 ms 492 KB Output is correct
17 Correct 39 ms 364 KB Output is correct
18 Correct 63 ms 364 KB Output is correct
19 Correct 37 ms 364 KB Output is correct
20 Correct 37 ms 364 KB Output is correct
21 Correct 38 ms 364 KB Output is correct
22 Correct 128 ms 396 KB Output is correct
23 Correct 41 ms 364 KB Output is correct
24 Correct 77 ms 364 KB Output is correct
25 Correct 81 ms 364 KB Output is correct
26 Correct 63 ms 396 KB Output is correct
27 Correct 98 ms 492 KB Output is correct
28 Correct 34 ms 364 KB Output is correct
29 Correct 29 ms 364 KB Output is correct
30 Correct 31 ms 364 KB Output is correct
31 Correct 51 ms 364 KB Output is correct
32 Correct 68 ms 364 KB Output is correct
33 Correct 74 ms 364 KB Output is correct
34 Correct 23 ms 364 KB Output is correct
35 Correct 5 ms 364 KB Output is correct
36 Correct 27 ms 492 KB Output is correct
37 Correct 35 ms 620 KB Output is correct
38 Correct 44 ms 364 KB Output is correct
39 Incorrect 44 ms 3776 KB Output isn't correct
40 Halted 0 ms 0 KB -