답안 #943978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943978 2024-03-12T05:57:38 Z Amaarsaa 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
2000 ms 4444 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair < ll, ll >;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
	int i, x, c, y, s, p, X;
	vector < pair < int,ll > > adj[N + 2];
	
	for (i = 0; i < M; i ++) {
		R[i][0] ++;
		R[i][1] ++;
		x = R[i][0];
		y = R[i][1];
		adj[x].push_back({y, L[i]});
		adj[y].push_back({x, L[i]});
	}
	priority_queue < pll, vector < pll > , greater < pll > > pq;
	vector < array < ll, 2> > D(N + 2);
	for (i = 1; i <= N; i ++) D[i] = {1000000000, 1000000000};
	for (i = 0; i < K; i ++) {
		P[i] ++;
		pq.push({0, P[i]});
		D[P[i]] = {0, 0};
	}
	
	while(!pq.empty()) {
		x = pq.top().second;
		c = pq.top().first;
		pq.pop();
		if ( D[x][1] != c) continue;
		
		for ( pair < int, ll > & pa : adj[x]) {
			X = pa.first;
			s = c + pa.second;
			p = D[X][1];
			if ( s >= D[X][0]) {
				if ( D[X][0] < 1e9 && D[X][1] != D[X][0]) {
					D[X][1]= D[X][0];
					pq.push({D[X][1], X});
				
				}
				D[X][0] = s;
			}
			else {
				if ( s > D[x][1]) {
					D[X][1] = s;
					pq.push({D[X][1], X});
				}
			}
		}
	}
  	return D[1][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:7:21: warning: variable 'p' set but not used [-Wunused-but-set-variable]
    7 |  int i, x, c, y, s, p, X;
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -