Submission #1041774

# Submission time Handle Problem Language Result Execution time Memory
1041774 2024-08-02T08:02:41 Z stdfloat Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 10860 KB
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;

using ll = long long;

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

int 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 (int 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) {
    // cout << endl << "X " << X << ' ' << Y << endl;

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

        // cout << endl << "md " << md << endl;

        // cout << "bfsx" << endl;

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

            // cout << "x " << x << ' ' << p[x] << endl;

            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;
        }

        // cout << endl << "bfsY" << endl;
        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();
        
            // cout << "x " << x << ' ' << p << endl;

            for (auto [i, w] : E[x]) {
                if (i == p || w > md) continue;

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

        // cout << "tr " << tr << endl;

        int x = Y;
        // cout << "gayt" << endl;
        while (x != X && !tr) {
            x = p[x];
            if (x == -1) break;

            int cnt = 0;
            for (auto [i, w] : E[x]) {
                if ((cnt += (w <= md)) > 2) break;
            }

            // cout << endl << "x " << x << ' ' << cnt << endl;

            tr = (cnt > 2);
        }

        // cout << "tr " << tr << endl;

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

    // cout << endl << "l " << l << endl;
    return (l == (int)1e9 + 1 ? -1 : l);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 3 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 181 ms 6488 KB Output is correct
10 Correct 437 ms 7772 KB Output is correct
11 Correct 687 ms 7772 KB Output is correct
12 Correct 664 ms 8280 KB Output is correct
13 Correct 900 ms 8044 KB Output is correct
14 Execution timed out 2051 ms 6488 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2045 ms 10860 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 3 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 504 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 3 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 4 ms 348 KB Output is correct
10 Correct 181 ms 6488 KB Output is correct
11 Correct 437 ms 7772 KB Output is correct
12 Correct 687 ms 7772 KB Output is correct
13 Correct 664 ms 8280 KB Output is correct
14 Correct 900 ms 8044 KB Output is correct
15 Correct 1 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 504 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 3 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 181 ms 6488 KB Output is correct
10 Correct 437 ms 7772 KB Output is correct
11 Correct 687 ms 7772 KB Output is correct
12 Correct 664 ms 8280 KB Output is correct
13 Correct 900 ms 8044 KB Output is correct
14 Execution timed out 2051 ms 6488 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 3 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 4 ms 348 KB Output is correct
10 Correct 181 ms 6488 KB Output is correct
11 Correct 437 ms 7772 KB Output is correct
12 Correct 687 ms 7772 KB Output is correct
13 Correct 664 ms 8280 KB Output is correct
14 Correct 900 ms 8044 KB Output is correct
15 Execution timed out 2051 ms 6488 KB Time limit exceeded
16 Halted 0 ms 0 KB -