답안 #51991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51991 2018-06-22T22:22:28 Z gs13105 악어의 지하 도시 (IOI11_crocodile) C++17
89 / 100
978 ms 119200 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct edg
{
    int x;
    long long w;
    bool operator <(const edg &a) const
    {
        return w > a.w;
    }
};

vector<edg> arr[100010];
edg dis[100010][2];
long long INF = 1e15;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for(int i = 0; i < M; i++)
    {
        int x = R[i][0];
        int y = R[i][1];
        int w = L[i];
        arr[x].push_back({ y, w });
        arr[y].push_back({ x, w });
    }

    for(int i = 0; i < N; i++)
        dis[i][0] = dis[i][1] = { i, INF };

    priority_queue<edg> pq;
    for(int i = 0; i < K; i++)
    {
        int x = P[i];
        dis[x][0] = dis[x][1] = { x, 0 };
        pq.push({ x, 0 });
    }

    while(!pq.empty())
    {
        int x = pq.top().x;
        long long w = pq.top().w;
        pq.pop();

        if(w > dis[x][1].w)
            continue;
        
        for(edg e : arr[x])
        {
            long long nw = w + e.w;
            if(nw < dis[e.x][0].w && x != dis[e.x][0].x)
            {
                dis[e.x][1] = dis[e.x][0];
                dis[e.x][0] = { x, nw };
                if(dis[e.x][1].w != INF)
                    pq.push({ e.x, dis[e.x][1].w });
            }
            else if(nw < dis[e.x][1].w && x != dis[e.x][1].x)
            {
                dis[e.x][1] = { x, nw };
                if(dis[e.x][1].w != INF)
                    pq.push({ e.x, dis[e.x][1].w });
            }
        }
    }

    assert(dis[0][1].w != INF);
    return dis[0][1].w;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2832 KB Output is correct
4 Correct 4 ms 2984 KB Output is correct
5 Correct 5 ms 2984 KB Output is correct
6 Correct 4 ms 3100 KB Output is correct
7 Correct 4 ms 3100 KB Output is correct
8 Correct 5 ms 3252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2832 KB Output is correct
4 Correct 4 ms 2984 KB Output is correct
5 Correct 5 ms 2984 KB Output is correct
6 Correct 4 ms 3100 KB Output is correct
7 Correct 4 ms 3100 KB Output is correct
8 Correct 5 ms 3252 KB Output is correct
9 Correct 6 ms 3500 KB Output is correct
10 Correct 4 ms 3500 KB Output is correct
11 Correct 5 ms 3500 KB Output is correct
12 Correct 9 ms 4000 KB Output is correct
13 Correct 8 ms 4244 KB Output is correct
14 Correct 4 ms 4244 KB Output is correct
15 Correct 5 ms 4244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2832 KB Output is correct
4 Correct 4 ms 2984 KB Output is correct
5 Correct 5 ms 2984 KB Output is correct
6 Correct 4 ms 3100 KB Output is correct
7 Correct 4 ms 3100 KB Output is correct
8 Correct 5 ms 3252 KB Output is correct
9 Correct 6 ms 3500 KB Output is correct
10 Correct 4 ms 3500 KB Output is correct
11 Correct 5 ms 3500 KB Output is correct
12 Correct 9 ms 4000 KB Output is correct
13 Correct 8 ms 4244 KB Output is correct
14 Correct 4 ms 4244 KB Output is correct
15 Correct 5 ms 4244 KB Output is correct
16 Correct 650 ms 84220 KB Output is correct
17 Correct 101 ms 84220 KB Output is correct
18 Correct 138 ms 84220 KB Output is correct
19 Correct 978 ms 114392 KB Output is correct
20 Correct 432 ms 114392 KB Output is correct
21 Correct 65 ms 114392 KB Output is correct
22 Incorrect 390 ms 119200 KB Output isn't correct