답안 #72704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72704 2018-08-26T16:51:04 Z chpipis 악어의 지하 도시 (IOI11_crocodile) C++11
100 / 100
1296 ms 59676 KB
//#include "grader.h"
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;

const int MAXN = 1e5 + 5;

vii gr[MAXN];
ll dist[MAXN];
bool visit[MAXN];
ll mn[MAXN];

const ll INF = 1e15;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    fill(gr, gr + MAXN, vii());
    for (int i = 0; i < M; i++) {
        gr[R[i][0]].pb(mp(R[i][1], L[i]));
        gr[R[i][1]].pb(mp(R[i][0], L[i]));
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
    fill(dist, dist + MAXN, INF);
    memset(visit, false, sizeof visit);

    for (int i = 0; i < K; i++) {
        visit[P[i]] = true;
        pq.push(mp(0, P[i]));
    }

    while (!pq.empty()) {
        ll w = pq.top().fi;
        int u = pq.top().se;
        pq.pop();

        if (visit[u]) {
            if (dist[u] == INF) {
                dist[u] = w;
            } else {
                continue;
            }
        } else {
            visit[u] = true;
            continue;
        }

        for (auto v : gr[u]) {
            if (dist[v.fi] == INF) {
                pq.push(mp(w + v.se, v.fi));
            }
        }
    }

    return dist[0];
    /*
    fill(mn, mn + MAXN, INF);

    for (int i = 0; i < K; i++) {
        mn[P[i]] = 0;
        dist[P[i]] = 0;
        pq.push(mp(0, P[i]));
    }

    while (!pq.empty()) {
        ll w = pq.top().fi;
        int u = pq.top().se;
        pq.pop();

        if (dist[u] < w) continue;

        for (auto v : gr[u]) {
            ll cost = w + ( ll )v.se;
            if (cost < mn[v.fi] || cost < dist[v.fi]) {
                if (cost < mn[v.fi]) {
                    dist[v.fi] = mn[v.fi];
                    mn[v.fi] = cost;
                } else if (cost < dist[v.fi]) {
                    dist[v.fi] = cost;
                }
                if (dist[v.fi] < INF)
                    pq.push(mp(dist[v.fi], v.fi));
            }
        }
    }

    assert(dist[0] < INF);

    return (int)dist[0];
    */
}


# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3576 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3632 KB Output is correct
4 Correct 8 ms 3760 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 7 ms 3796 KB Output is correct
7 Correct 8 ms 3872 KB Output is correct
8 Correct 9 ms 3872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3576 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3632 KB Output is correct
4 Correct 8 ms 3760 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 7 ms 3796 KB Output is correct
7 Correct 8 ms 3872 KB Output is correct
8 Correct 9 ms 3872 KB Output is correct
9 Correct 10 ms 4204 KB Output is correct
10 Correct 7 ms 4204 KB Output is correct
11 Correct 9 ms 4204 KB Output is correct
12 Correct 19 ms 4460 KB Output is correct
13 Correct 12 ms 4588 KB Output is correct
14 Correct 7 ms 4588 KB Output is correct
15 Correct 6 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3576 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3632 KB Output is correct
4 Correct 8 ms 3760 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 7 ms 3796 KB Output is correct
7 Correct 8 ms 3872 KB Output is correct
8 Correct 9 ms 3872 KB Output is correct
9 Correct 10 ms 4204 KB Output is correct
10 Correct 7 ms 4204 KB Output is correct
11 Correct 9 ms 4204 KB Output is correct
12 Correct 19 ms 4460 KB Output is correct
13 Correct 12 ms 4588 KB Output is correct
14 Correct 7 ms 4588 KB Output is correct
15 Correct 6 ms 4588 KB Output is correct
16 Correct 1296 ms 57312 KB Output is correct
17 Correct 106 ms 57312 KB Output is correct
18 Correct 163 ms 57312 KB Output is correct
19 Correct 1225 ms 59676 KB Output is correct
20 Correct 661 ms 59676 KB Output is correct
21 Correct 61 ms 59676 KB Output is correct
22 Correct 568 ms 59676 KB Output is correct