제출 #1368326

#제출 시각아이디문제언어결과실행 시간메모리
1368326yonatanl자매 도시 (APIO20_swap)C++20
0 / 100
0 ms344 KiB
#include "swap.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <iomanip>

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define upmax(a, b) a = max(a, b)
#define upmin(a, b) a = min(a, b)

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll n, m;
vvpll g;
vvll dp;

void dijkstra(ll x, ll y) {
    dp.clear();
    dp.resize(n, vll(n, INF));
    dp[x][y] = 0;
    priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> pq;
    pq.push({ 0, {x, y} });
    while (!pq.empty()) {
        ll cur_x = pq.top().second.first;
        ll cur_y = pq.top().second.second;
        ll max_edge = pq.top().first;
        pq.pop();
        for (auto& it : g[cur_x]) {
            ll next_x = it.first;
            ll w = it.second;
            if (next_x == cur_y) continue;
            if (max(w, max_edge) < dp[next_x][cur_y]) {
                dp[next_x][cur_y] = max(w, max_edge);
                pq.push({ dp[next_x][cur_y], {next_x, cur_y} });
            }
        }
        for (auto& it : g[cur_y]) {
            ll next_y = it.first;
            ll w = it.second;
            if (next_y == cur_x) continue;
            if (max(w, max_edge) < dp[cur_x][next_y]) {
                dp[cur_x][next_y] = max(w, max_edge);
                pq.push({ dp[cur_x][next_y], {cur_x, next_y} });
            }
        }
    }
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N, m = M;
    g.clear(), g.resize(n);
    rep(i, 0, m) {
        g[U[i]].push_back({ V[i], W[i] });
        g[V[i]].push_back({ U[i], W[i] });
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    ll x = X, y = Y;
    dijkstra(x, y);
    return dp[y][x];
}

/*
5 4
0 1 3
0 2 10
0 3 5
0 4 4
8
0 1
0 2
0 3
0 4
1 2
1 3
1 4
2 3

5 6 
0 1 4 
0 2 4 
1 2 1 
1 3 2
1 4 10 
2 3 3 
3
1 2 
2 4 
0 1 
*/
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…