답안 #1041837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041837 2024-08-02T08:39:09 Z stdfloat 자매 도시 (APIO20_swap) C++17
0 / 100
2000 ms 12648 KB
#include <bits/stdc++.h>
#include "swap.h"
// #include "grader.cpp"
using namespace std;

using ll = long long;

#define ff  first
#define ss  second
#define pii pair<ll, ll>

ll n;

vector<vector<pii>> E;

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    E.assign(n, {});
    for (ll i = 0; i < M; i++) {
        E[U[i]].push_back({V[i], W[i]});
        E[V[i]].push_back({U[i], W[i]});
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    ll l = 0, r = (ll)1e9 + 1;
    while (l < r) {
        ll md = (l + r) >> 1;

        queue<ll> q;
        vector<bool> visX(n);
        vector<ll> p(n, -1);
        q.push(X); visX[X] = true;
        while (!q.empty()) {
            ll x = q.front(); q.pop();

            for (auto [i, w] : E[x]) {
                if (w <= md && !visX[i]) {
                    p[i] = x;
                    q.push(i);
                    visX[i] = true;
                }
            }
        }

        if (!visX[Y]) {
            l = md + 1;
            continue;
        }

        bool tr = false;
        vector<bool> visY(n);
        queue<pii> q1;
        q1.push({Y, -1}); visY[Y] = true;
        while (!q1.empty() && !tr) {
            auto [x, p] = q1.front(); q1.pop();
        
            for (auto [i, w] : E[x]) {
                if (w > md || i == p) continue;

                if (visY[i]) {
                    if (visX[i]) {
                        tr = true;
                        break;
                    }
                }
                else {
                    visY[i] = true;
                    q1.push({i, x});
                }
            }
        }

        ll x = Y;
        while (x != X && !tr) {
            x = p[x];

            ll cnt = 0;
            for (auto [i, w] : E[x]) {
                cnt += (w <= md);
            }

            tr = (cnt > 2);
        }

        if (!tr) l = md + 1;
        else r = md;
    }

    return (l == (ll)1e9 + 1 ? -1 : l);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 157 ms 8032 KB Output is correct
10 Correct 404 ms 9856 KB Output is correct
11 Correct 624 ms 9640 KB Output is correct
12 Correct 589 ms 10320 KB Output is correct
13 Correct 743 ms 10324 KB Output is correct
14 Execution timed out 2068 ms 8284 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2066 ms 12648 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Incorrect 2 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 157 ms 8032 KB Output is correct
11 Correct 404 ms 9856 KB Output is correct
12 Correct 624 ms 9640 KB Output is correct
13 Correct 589 ms 10320 KB Output is correct
14 Correct 743 ms 10324 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Incorrect 2 ms 348 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 157 ms 8032 KB Output is correct
10 Correct 404 ms 9856 KB Output is correct
11 Correct 624 ms 9640 KB Output is correct
12 Correct 589 ms 10320 KB Output is correct
13 Correct 743 ms 10324 KB Output is correct
14 Execution timed out 2068 ms 8284 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 157 ms 8032 KB Output is correct
11 Correct 404 ms 9856 KB Output is correct
12 Correct 624 ms 9640 KB Output is correct
13 Correct 589 ms 10320 KB Output is correct
14 Correct 743 ms 10324 KB Output is correct
15 Execution timed out 2068 ms 8284 KB Time limit exceeded
16 Halted 0 ms 0 KB -