답안 #200653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200653 2020-02-07T21:27:46 Z DavidDamian 악어의 지하 도시 (IOI11_crocodile) C++11
0 / 100
7 ms 2680 KB
#include"crocodile.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge
{
    int to;
    ll w;
};
vector<edge> adjList[100005];
ll first[100005]; //Shortest path to that node from an exit
ll second[100005]; //Second shortest path to that node from an exit
struct node
{
    int data;
    ll key;
};
bool operator<(const node& a,const node& b)
{
    return a.key<b.key;
}
priority_queue<node> Q;
void relax(int u,int v,ll w)
{
    if(second[u]+w<first[v]){
        second[v]=first[v];
        first[v]=second[u]+w;
        node x={v,second[v]};
        Q.push(x);
    }
    else if(second[u]+w<second[v]){
        second[v]=second[u]+w;
        node x={v,second[v]};
        Q.push(x);
    }
}
void dijkstra(int n,int k,int P[])
{
    for(int i=0;i<n;i++){
        first[i]=second[i]=LLONG_MAX;
    }
    for(int i=0;i<k;i++){
        int u=P[i];
        first[u]=second[u]=0;
        node x={u,0};
        Q.push(x);
    }
    while(Q.size()){
        node u=Q.top();Q.pop();
        if(u.key==LLONG_MAX) continue;
        for(edge e: adjList[u.data]){
            if(e.to!=0 && adjList[e.to].size()==2) continue;
            relax(u.data,e.to,e.w);
        }
    }
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for(int i=0;i<M;i++){
        int u=R[i][0];
        int v=R[i][1];
        edge e={v,L[i]};
        adjList[u].push_back(e);
        e.to=u;
        adjList[v].push_back(e);
    }
    dijkstra(N,K,P);
    for(int i=0;i<N;i++){
        cout<<first[i]<<" "<<second[i]<<endl;
    }
    int secondBest=second[0];
    return secondBest;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -