답안 #745972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745972 2023-05-21T10:15:37 Z vjudge1 Cities (BOI16_cities) C++17
0 / 100
408 ms 18184 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;

struct edge {
	ll to;
	ll w;
	bool operator<(const edge& e)const {
		return w > e.w;
	}
};

const ll maxn = 100001;

vector<edge> g[maxn];
void dijkstra(ll a, vector<ll>& da) {
	priority_queue<edge> q;
	q.push({ a, 0 });
	da[a] = 0;
	while (!q.empty()) {
		edge e = q.top();
		q.pop();
		if (da[e.to] < e.w)continue;
		for (edge i : g[e.to]) {
			if (da[i.to] < 0 || da[i.to] > da[e.to] + i.w) {
				da[i.to] = da[e.to] + i.w;
				q.push({ i.to, da[i.to] });
			}
		}
	}
	return;
}


int main()
{
	ll n, k, m;
	cin >> n >> k >> m;
	ll a, b, c;
	cin >> a >> b >> c;
	for (ll i = 0; i < m; i++) {
		ll a, b;
		ll w;
		cin >> a >> b >> w;
		g[a].push_back({ b, w });
		g[b].push_back({ a, w });
	}
	vector<ll> da(n + 1, -1), db(n + 1, -1), dc(n + 1, -1);
	dijkstra(a, da);
	dijkstra(b, db);
	dijkstra(c, dc);

	ll ans = INT64_MAX;
	for (ll i = 1; i <= n; i++) {
		ans = min(ans, da[i] + db[i] + dc[i]);
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 370 ms 17624 KB Output is correct
2 Correct 408 ms 18184 KB Output is correct
3 Correct 181 ms 10496 KB Output is correct
4 Correct 170 ms 11940 KB Output is correct
5 Runtime error 4 ms 5076 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 5076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 5076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -