제출 #153105

#제출 시각아이디문제언어결과실행 시간메모리
153105mhy908악어의 지하 도시 (IOI11_crocodile)C++14
100 / 100
899 ms94340 KiB
#include "crocodile.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define inf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m, k;
vector<pair<int, LL> > link[100010];
LL dijk[100010][3];
bool ch[100010];
priority_queue<pair<LL, int> >pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    n=N;
    m=M;
    k=K;
    for(int i=0; i<m; i++){
        link[R[i][0]+1].pb(make_pair(R[i][1]+1, (LL)L[i]));
        link[R[i][1]+1].pb(make_pair(R[i][0]+1, (LL)L[i]));
    }
    for(int i=1; i<=n; i++)dijk[i][1]=dijk[i][2]=inf;
    for(int i=0; i<k; i++)dijk[P[i]+1][1]=dijk[P[i]+1][2]=0, pq.push(make_pair(0, +P[i]+1));
    while(!pq.empty()){
        int here=pq.top().S;
        LL c=-pq.top().F;
        pq.pop();
        if(ch[here])continue;
        ch[here]=true;
        for(int i=0; i<link[here].size(); i++){
            int next=link[here][i].F;
            LL cost=link[here][i].S;
            if(ch[next])continue;
            if(dijk[next][1]>c+cost){
                dijk[next][2]=dijk[next][1];
                dijk[next][1]=c+cost;
                pq.push(make_pair(-dijk[next][2], next));
            }
            else if(dijk[next][2]>c+cost){
                dijk[next][2]=c+cost;
                pq.push(make_pair(-dijk[next][2], next));
            }
        }
    }
    return (int)dijk[1][2];
}

/*
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1
3
14
*/

컴파일 시 표준 에러 (stderr) 메시지

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<link[here].size(); i++){
                      ~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...