답안 #717686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717686 2023-04-02T10:45:49 Z hafo 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
4 ms 4952 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;

int n, m, r[maxn][2], l[maxn], k, p[maxn];
pair<ll, ll> f[maxn];
vector<pa> g[maxn];

struct state {
    pair<ll, ll> cost;
    int u;
    friend bool operator < (state a, state b) {
        return a.cost > b.cost;
    }
};

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    priority_queue<state, vector<state>> q;
    fill_n(f, n + 1, make_pair(oo, oo));
    for(int i = 0; i < k; i++) {
        f[p[i]] = {0, 0};
        q.push({f[p[i]], p[i]});
    }

    for(int i = 0; i < m; i++) {
        int u = r[i][0], v = r[i][1];
        g[u].pb({v, l[i]});
        g[v].pb({u, l[i]});
    }

    while(!q.empty()) {
        int u = q.top().u;
        auto fu = q.top().cost;
        q.pop();

        if(fu != f[u]) continue;
        for(auto e:g[u]) {
            int v = e.fi, w = e.se;
            if(f[v].fi >= fu.se + w) {
                f[v].se = f[v].fi;
                f[v].fi = fu.se + w;
                q.push({f[v], v});
            } else if(f[v].se >= fu.se + w) {
                f[v].se = fu.se + w;
                q.push({f[v], v});
            }
        }
    }
    return f[0].se;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Incorrect 4 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Incorrect 4 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Incorrect 4 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -