답안 #758267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758267 2023-06-14T10:44:44 Z ivaziva 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
2 ms 4180 KB
#include <bits/stdc++.h>
#include "crocodile.h"

using namespace std;

#define MAXN 100010

long long n;
long long m;
long long k;
vector<pair<long long,long long>> adj[MAXN];
long long pos[MAXN];
priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
long long dist1[MAXN];
long long dist2[MAXN];
long long niz[MAXN];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    n=N; m=M; k=K;
    for (long long i=1;i<=m;i++)
    {
        long long x;
        long long y;
        long long z;
        x=R[i-1][0];
        y=R[i-1][0];
        z=L[i-1];
        adj[x].push_back({y,z});
        adj[y].push_back({x,z});
    }
    for (long long i=0;i<MAXN;i++)
    {
        dist1[i]=LLONG_MAX;
        dist2[i]=LLONG_MAX;
    }
    for (long long i=1;i<=k;i++)
    {
        niz[i]=P[i-1];
        dist1[niz[i]]=0;
        dist2[niz[i]]=0;
        pq.push({0,niz[i]});
        pos[niz[i]]=1;
    }
    while (pq.empty()==false)
    {
        long long node0=pq.top().second;
        long long dist0=pq.top().first;
        pq.pop();
        if (dist2[node0]<dist0) continue;
        if (pos[node0]>1) continue;
        if (pos[node0]==1)
        {
            long long s=adj[node0].size();
            for (long long i=0;i<s;i++)
            {
                long long node=adj[node0][i].first;
                long long dist=adj[node0][i].second;
                if (dist0+dist<dist1[node])
                {
                    dist2[node]=dist1[node];
                    dist1[node]=dist0+dist;
                    pq.push({dist1[node],node});
                }
                else if (dist0+dist<dist2[node])
                {
                    dist2[node]=dist+dist0;
                    pq.push({dist2[node],node});
                }
            }
        }
        pos[node0]++;
    }
    return dist2[0];
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -