제출 #228256

#제출 시각아이디문제언어결과실행 시간메모리
228256pavementCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
363 ms23184 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, M, S, T, U, V, a, d, minst = LLONG_MAX, mined = LLONG_MAX, distS[100005], distT[100005], distU[100005], distV[100005];
vector<ii> adj[100005];
iii ed[200005];
priority_queue<ii, vector<ii>, greater<ii> > pq;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M >> S >> T >> U >> V;
	for (int A, B, C, i = 1; i <= M; i++) {
		cin >> A >> B >> C;
		adj[A].eb(B, C);
		adj[B].eb(A, C);
		ed[i] = mt(A, B, C);
	}
	memset(distS, 127, sizeof distS);
	memset(distT, 127, sizeof distT);
	memset(distU, 127, sizeof distU);
	memset(distV, 127, sizeof distV);
	distS[S] = 0;
	pq.emplace(0, S);
	while (!pq.empty()) {
		d = pq.top().first, a = pq.top().second;
		pq.pop();
		if (d > distS[a]) continue;
		for (auto u : adj[a])
			if (distS[u.first] > d + u.second) {
				distS[u.first] = d + u.second;
				pq.emplace(distS[u.first], u.first);
			}
	}
	distT[T] = 0;
	pq.emplace(0, T);
	while (!pq.empty()) {
		d = pq.top().first, a = pq.top().second;
		pq.pop();
		if (d > distT[a]) continue;
		for (auto u : adj[a])
			if (distT[u.first] > d + u.second) {
				distT[u.first] = d + u.second;
				pq.emplace(distT[u.first], u.first);
			}
	}
	distU[U] = 0;
	pq.emplace(0, U);
	while (!pq.empty()) {
		d = pq.top().first, a = pq.top().second;
		pq.pop();
		if (d > distU[a]) continue;
		for (auto u : adj[a])
			if (distU[u.first] > d + u.second) {
				distU[u.first] = d + u.second;
				pq.emplace(distU[u.first], u.first);
			}
	}
	distV[V] = 0;
	pq.emplace(0, V);
	while (!pq.empty()) {
		d = pq.top().first, a = pq.top().second;
		pq.pop();
		if (d > distV[a]) continue;
		for (auto u : adj[a])
			if (distV[u.first] > d + u.second) {
				distV[u.first] = d + u.second;
				pq.emplace(distV[u.first], u.first);
			}
	}
	for (int A, B, C, i = 1; i <= M; i++) {
		tie(A, B, C) = ed[i];
		if (distT[B] + distS[A] + C == distS[T]) {
			minst = min(minst, distU[A]);
			mined = min(mined, distV[B]);
		}
		swap(A, B);
		if (distT[B] + distS[A] + C == distS[T]) {
			minst = min(minst, distU[A]);
			mined = min(mined, distV[B]);
		}
	}
	cout << min(distU[V], minst + mined) << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...