Submission #633598

# Submission time Handle Problem Language Result Execution time Memory
633598 2022-08-22T19:30:07 Z l_reho Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
563 ms 89144 KB
#include "crocodile.h"

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

#define ll long long
vector<pair<ll, ll>> dp; // best,  second_best
vector<vector<pair<int, ll>>> graph;
vector<bool> visited;
int inf = 1e9+5;

struct info{
	int node;
	int start;
	ll dist;
	
	bool operator< (const info& rhs) const {
        return dist > rhs.dist;
    }
	
};

void dijkstra(vector<int> ends){
	
	priority_queue<info> pq;
	
	
	for(int e : ends)
		pq.push({e, e, 0}), dp[e] = {0, 0};
	
	while(!pq.empty()){
		
		info p = pq.top();
	
		pq.pop();
		
		vector<pair<int, ll>> adj = graph[p.node];
		
		if(p.dist > dp[p.node].second) continue;
		
		for(pair<int, int> a : adj){
			int prev = dp[a.first].second;
			if(p.dist + a.second < dp[a.first].first){
				dp[a.first].second = dp[a.first].first;
				dp[a.first].first = p.dist + a.second;
				
				// pq.push({a.first, p.start, dp[a.first].first});
			}else if(p.dist + a.second < dp[a.first].second){
				dp[a.first].second = p.dist + a.second;
			}
			
			if(dp[a.first].second < prev) pq.push({a.first, p.start, dp[a.first].second});
			
				
		}
	}

	
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
	dp.assign(N, {inf, inf});
	visited.assign(N, 0);
	
	graph.assign(N, vector<pair<int, ll>>());
	
	for(int i = 0; i < M; i++){
		graph[R[i][0]].push_back({R[i][1], L[i]});
		graph[R[i][1]].push_back({R[i][0], L[i]});
		
	}
	vector<int> ends;
	unordered_map<int, bool> end;
	for(int i = 0; i < K; i++)
		ends.push_back(P[i]), end[P[i]] = true;
		
	dijkstra(ends);
	if(dp[0].second == inf) return -1;
	return dp[0].second;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
16 Correct 438 ms 81632 KB Output is correct
17 Correct 68 ms 17612 KB Output is correct
18 Correct 92 ms 20128 KB Output is correct
19 Correct 563 ms 89144 KB Output is correct
20 Correct 263 ms 65316 KB Output is correct
21 Correct 42 ms 8016 KB Output is correct
22 Correct 286 ms 62464 KB Output is correct