Submission #50988

# Submission time Handle Problem Language Result Execution time Memory
50988 2018-06-15T11:25:10 Z aquablitz11 Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
851 ms 102160 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;

#define F first
#define S second

const int N = 150010;
const ll INF = 1e18;

ll dist1[N], dist2[N];
bool vis[N];
vector<pii> G[N];

int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
    fill(dist1, dist1+n, INF);
    fill(dist2, dist2+n, INF);
    for (int i = 0; i < m; ++i) {
        int u = R[i][0], v = R[i][1], w = L[i];
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }

    priority_queue<pli, vector<pli>, greater<pli>> Q;
    for (int i = 0; i < k; ++i) {
        dist1[P[i]] = dist2[P[i]] = 0;
        Q.push({0, P[i]});
    }

    while (!Q.empty()) {
        int u = Q.top().second;
        Q.pop();
        if (vis[u]) continue;
        vis[u] = true;
        for (auto v : G[u]) if (!vis[v.F]) {
            bool mod = false;
            if (dist2[u]+v.S < dist1[v.F]) {
                dist2[v.F] = dist1[v.F];
                dist1[v.F] = dist2[u]+v.S;
                mod = true;
            } else if (dist2[u]+v.S < dist2[v.F]) {
                dist2[v.F] = dist2[u]+v.S;
                mod = true;
            }
            if (mod && dist2[v.F] < INF)
                Q.push({dist2[v.F], v.F});
        }
    }

    return dist2[0];
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3944 KB Output is correct
3 Correct 5 ms 4100 KB Output is correct
4 Correct 6 ms 4200 KB Output is correct
5 Correct 5 ms 4320 KB Output is correct
6 Correct 6 ms 4320 KB Output is correct
7 Correct 6 ms 4428 KB Output is correct
8 Correct 6 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4592 KB Output is correct
2 Correct 5 ms 4592 KB Output is correct
3 Correct 6 ms 4656 KB Output is correct
4 Correct 9 ms 5000 KB Output is correct
5 Correct 9 ms 5176 KB Output is correct
6 Correct 5 ms 5176 KB Output is correct
7 Correct 6 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 60612 KB Output is correct
2 Correct 100 ms 60612 KB Output is correct
3 Correct 128 ms 60612 KB Output is correct
4 Correct 851 ms 89316 KB Output is correct
5 Correct 439 ms 90940 KB Output is correct
6 Correct 50 ms 90940 KB Output is correct
7 Correct 427 ms 102160 KB Output is correct