답안 #99539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99539 2019-03-04T20:16:30 Z jhnah917 악어의 지하 도시 (IOI11_crocodile) C++14
컴파일 오류
0 ms 0 KB
#include "crocodile.h"
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef pair<int, int> p;
vector<p> g[101010];
priority_queue<p> pq;
int dist1[101010], dist2[101010];
int visit[101010];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
	for(int i=0; i<=n; i++) dist1[i] = dist2[i] = 1e9+7;
	for(int i=0; i<m; i++){
		int s = R[i][0], e = R[i][1], w = L[i];
		g[s].push_back({e, w});
		g[e].push_back({s, w});
	}
	for(int i=0; i<k; i++){
		dist1[P[i]] = dist2[P[i]] = 0;
		pq.push({0, P[i]});
	}
	
	while(!pq.empty()){
		int now = pq.top().second, cost = -pq.top().first;
		pq.pop();
		if(visit[now]) continue;
		visit[now] = 1;
		
		for(auto i : g[now]){
			int nxt = i.first, nxtCost = i.second;
			if(visit[nxt]) continue;
			//first
			if(dist1[nxt] > dist2[now] + nxtCost){
				dist2[nxt] = dist1[nxt];
				dist1[nxt] = dist2[now] + nxtCost;
				if(dist2[nxt] < 1e9+7) pq.push({-dist2[nxt], nxt});
			}
			//second
			else if(dist2[nxt] > dist2[now] + nxtCost){
				dist2[nxt] = dist2[now] + nxtCost;
				pq.push({-dist2[nxt], nxt});
			}
		}
	}
	
	return dist2[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:14:18: error: 'n' was not declared in this scope
  for(int i=0; i<=n; i++) dist1[i] = dist2[i] = 1e9+7;
                  ^
crocodile.cpp:15:17: error: 'm' was not declared in this scope
  for(int i=0; i<m; i++){
                 ^
crocodile.cpp:20:17: error: 'k' was not declared in this scope
  for(int i=0; i<k; i++){
                 ^
crocodile.cpp:26:30: warning: unused variable 'cost' [-Wunused-variable]
   int now = pq.top().second, cost = -pq.top().first;
                              ^~~~