답안 #322552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322552 2020-11-14T19:25:30 Z Farrius 악어의 지하 도시 (IOI11_crocodile) C++11
0 / 100
1 ms 364 KB
#include "crocodile.h"
#include <bits/stdc++.h>

#define len(x) (int) x.size()
#define f first
#define s second
using namespace std;
using ll = long long;
using ld = long double;

const int INF = 1e9;

int travel_plan (int n, int m, int r[][2], int l[], int k, int p[]) {
	//make graph
	vector<pair<int, int>> g[n];
	for (int i = 0; i < m; i++) {
		int u = r[i][0], v = r[i][1];
		g[u].push_back(make_pair(v, l[i]));
		g[v].push_back(make_pair(u, l[i]));
	}
	//know how many exits have each vertex
	multiset<int> can_exit[n];
	for (int i = 0; i < k; i++) {
		for (auto u : g[p[i]]) {
			can_exit[u.first].insert(u.second);
		}
	}
	//dijkstra
	int sol = 1e9;
	vector<int> dist(n, INF);
	priority_queue<pair<int, int>> pq;
	bool vis[n];
	memset(vis, false, sizeof(vis));
	pq.push(make_pair(0, 0));
	dist[0] = 0;
	while (!pq.empty()) {
		int v = pq.top().s;
		int cur = -pq.top().f;
		pq.pop();
		if (vis[v]) continue;
		vis[v] = true;
		if (len(can_exit[v]) >= 2) {
			auto cost = can_exit[v].begin();
			cost++;
			sol = min(sol, *cost + cur);
		}
		for (auto u : g[v]) {
			if (dist[u.f] > dist[v] + u.s) {
				dist[u.f] = dist[v] + u.s;
				pq.push(make_pair(-dist[u.f], u.f));
			}
		}
	}
	return sol;
}
/*
int main () {
	int n, m, k;
	cin >> n >> m >> k;
	int l[m], r[m][2], p[k];
	for (int i = 0; i < m; i++) {
		cin >> r[i][0] >> r[i][1] >> l[i];
	}
	for (int i = 0; i < k; i++) {
		cin >> p[i];
	}
	cout << travel_plan(n, m, r, l, k, p) << " solution " << '\n';
}*/

# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -