답안 #379942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379942 2021-03-19T19:08:54 Z nikatamliani Relay Marathon (NOI20_relaymarathon) C++14
0 / 100
6000 ms 5904 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 < 4e8; ++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 Execution timed out 6025 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6025 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6036 ms 5904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6025 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -