제출 #1329076

#제출 시각아이디문제언어결과실행 시간메모리
1329076vache_kocharyanCrocodile's Underground City (IOI11_crocodile)C++20
0 / 100
1 ms344 KiB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define sort_uniq(x) sort(all(x)), uniq(x);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<int, int>
#define V vector
#define V2dll V<V<int>>
#define V2dchar V<V<char>>
#define V2dbool V<V<bool>>
#define V3dll V<V<V<int>>>
#define V3dchar V<V<V<char>>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define FASTIO                         \
  ios_base::sync_with_stdio(false);    \
  cin.tie(nullptr);                    \
  cout.tie(nullptr);
#define INF INT_MAX
#define blt __builtin_popcount
#define clr(x) x.clear()
#define ff first
#define ss second
#define popf pop_front
#define popb pop_back
#define sz(x) int(x.size())
#define rep(a, b, c, d) for (int a = b; a <= c; a += d)
#define repl(a, b, c, d) for (int a = b; a >= c; a -= d)

const int N = 1e5 + 5;
V<pii> adj[N];
int dp[N], bst[N];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	int n = N, m = M;
	rep(i, 0, M - 1, 1) {
		int x = R[i][0] + 1, y = R[i][1] + 1;
		int w = L[i];
		adj[x].pb({ y, w });
		adj[y].pb({ x, w });
	}

	priority_queue<pii, V<pii>, greater<pii>> pq;
	function<void(int)> update = [&](int node) -> void {
		int w = dp[node];
		//cout << node << " " << dp[node] << endl;
		for (auto bs : adj[node]) {
			int i = bs.ff, val = bs.ss;
			if (w + val < dp[i]) {
				if (w + val < bst[i]) {
					dp[i] = bst[i];
					bst[i] = w + val;
				}
				else {
					dp[i] = w + val;
				}
				//if (dp[i] < 1e9)
					pq.push({ dp[i], i });
			}
		}
		return;
		};

	rep(i, 1, n, 1) {
		dp[i] = bst[i] = 1e9;
	}
	rep(i, 0, K - 1, 1)
		dp[P[i] + 1] = 0, bst[P[i] + 1] = 0;

	rep(i, 0, K - 1, 1)
		pq.push({ 0, P[i] + 1 });
	while (!pq.empty()) {
		auto it = pq.top();
		pq.pop();
		int w = it.ff;
		int node = it.ss;
		//if (w > dp[node])
		//	continue;
		update(node);
	}
	return (int)dp[1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...