답안 #335926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335926 2020-12-14T10:03:52 Z enerelt14 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
2 ms 2668 KB
	#include "crocodile.h"
	#include<bits/stdc++.h>
	#define pb push_back
	#define mp make_pair
	#define ff first
	#define ss second
	using namespace std;
	vector<pair<int, int> >adj[100005];
	int path;
	int a[100005][3]={0}, s[100005];
	void dijkstra(int k){
	  	bool vis[100005];
	  	priority_queue<pair<int, int> >pq;
	  	pq.push(mp(0, k));
	  	while(!pq.empty()){
	      	int u = pq.top().ss;
	      	int cost = -pq.top().ff;
	      	pq.pop();
	      	if (s[u]>=2)path=min(cost+a[u][2], path);
	      	vis[u] = 1;
	      	for(int i = 0; i < adj[u].size(); i++){
	        	int v = adj[u][i].ff;
	          	int e = adj[u][i].ss;
	          	if(!vis[v]) pq.push(mp(-(cost + e), v));
	      	}
	      	while(!pq.empty() && vis[pq.top().ss]) pq.pop();
	  	}
	}
	int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
	{
		for (int i=0;i<M;i++){
			adj[R[i][0]].pb(mp(R[i][1], L[i]));
			adj[R[i][1]].pb(mp(R[i][0], L[i]));
		}
		for (int i=0;i<K;i++){
			for (int j=0;j<adj[P[i]].size();j++){
				int v=adj[P[i]][j].ff;
				int cost=adj[P[i]][j].ss;
				s[v]++;
				if (s[v]==1)a[v][1]=cost;
				if (s[v]==2){
					a[v][2]=max(a[v][1], cost);
					a[v][1]=min(a[v][1], cost);
				}
				if (s[v]>=3){
					if (cost<a[v][1]){
						a[v][2]=a[v][1];
						a[v][1]=cost;
					}
					if (cost>=a[v][1] && cost<a[v][2])a[v][2]=cost;
				}
			}
		}
		path=1000000001;
		dijkstra(0);
		return(path);
	}
	

Compilation message

crocodile.cpp: In function 'void dijkstra(int)':
crocodile.cpp:21:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int i = 0; i < adj[u].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    for (int j=0;j<adj[P[i]].size();j++){
      |                 ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -