제출 #205348

#제출 시각아이디문제언어결과실행 시간메모리
205348mode149256악어의 지하 도시 (IOI11_crocodile)C++11
89 / 100
868 ms73652 KiB
/*input

*/
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

const ll DID = (ll)1e17;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	vector<vpl> edges(N);
	{
		for (int i = 0; i < M; ++i)
		{
			int a = R[i][0];
			int b = R[i][1];
			edges[a].emplace_back(b, L[i]);
			edges[b].emplace_back(a, L[i]);
		}
	}

	vll dis(N, vl(2, DID));
	priority_queue<pl, vpl, greater<pl>> pq;

	for (int i = 0; i < K; ++i)
	{
		int c = P[i];
		dis[c][0] = dis[c][1] = 0;
		pq.push({0, c});
	}

	while (pq.size()) {
		pl dab = pq.top(); pq.pop();

		int c = (int)dab.y;
		ll d = dab.x;
		if (d > dis[c][1]) continue;

		for (auto u : edges[c]) {
			ll newDis = d + u.y;
			if (newDis <= dis[u.x][0]) {
				dis[u.x][1] = dis[u.x][0];
				dis[u.x][0] = newDis;

				if (dis[u.x][1] != DID)
					pq.push({dis[u.x][1], u.x});
			} else if (newDis < dis[u.x][1]) {
				dis[u.x][1] = newDis;
				pq.push({dis[u.x][1], u.x});
			}
		}
	}

	return dis[0][1];
}


/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...