Submission #1042629

# Submission time Handle Problem Language Result Execution time Memory
1042629 2024-08-03T08:48:41 Z stdfloat Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 13652 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) {
    int l = 0, r = (int)1e9 + 1;
    while (l < r) {
        int md = (l + r) >> 1;
 
        bool tr = false;
        queue<pii> q;
        vector<bool> visX(n);
        q.push({X, -1}); visX[X] = true;
        while (!q.empty()) {
            auto [x, pr] = q.front(); q.pop();
 
            for (auto [i, w] : E[x]) {
                if (i == pr || w > md || visX[i]) continue;
                // if (visX[i]) {
                //     if (i == X) {
                //         tr = true;
                //         break;
                //     }
                // }
                // else {
                    q.push({i, x});
                    visX[i] = true;
                // }
            }
        }
 
        if (!visX[Y]) {
            l = md + 1;
            continue;
        }
 
        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 (i == Y || visX[i]) {
                        tr = true;
                        break;
                    }
                }
                else {
                    visY[i] = true;
                    q1.push({i, x});
                }
            }
        }
 
        for (int i = 0; i < n && !tr; i++) {
            if (!visX[i] || !visY[i]) continue;

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

            tr = (cnt > 2);
        }
 
        if (!tr) l = md + 1;
        else r = md;
    }
 
    return (l == (int)1e9 + 1 ? -1 : l);
}
# Verdict Execution time Memory 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 2 ms 460 KB Output is correct
5 Correct 3 ms 344 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 161 ms 6576 KB Output is correct
10 Correct 427 ms 7772 KB Output is correct
11 Correct 637 ms 7772 KB Output is correct
12 Correct 584 ms 8016 KB Output is correct
13 Correct 888 ms 8024 KB Output is correct
14 Execution timed out 2067 ms 6704 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2054 ms 10352 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 2 ms 460 KB Output is correct
5 Correct 3 ms 344 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 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 512 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 1 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 2 ms 460 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 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 161 ms 6576 KB Output is correct
11 Correct 427 ms 7772 KB Output is correct
12 Correct 637 ms 7772 KB Output is correct
13 Correct 584 ms 8016 KB Output is correct
14 Correct 888 ms 8024 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 12 ms 1372 KB Output is correct
35 Correct 912 ms 8168 KB Output is correct
36 Correct 740 ms 8016 KB Output is correct
37 Correct 650 ms 8020 KB Output is correct
38 Correct 686 ms 8028 KB Output is correct
39 Correct 517 ms 8016 KB Output is correct
40 Correct 588 ms 7504 KB Output is correct
41 Correct 630 ms 8280 KB Output is correct
42 Correct 975 ms 8016 KB Output is correct
43 Correct 723 ms 8016 KB Output is correct
44 Correct 231 ms 8536 KB Output is correct
45 Correct 323 ms 10324 KB Output is correct
46 Correct 644 ms 8016 KB Output is correct
47 Correct 488 ms 8028 KB Output is correct
48 Correct 327 ms 8796 KB Output is correct
49 Correct 66 ms 9040 KB Output is correct
50 Correct 76 ms 6748 KB Output is correct
51 Correct 215 ms 8792 KB Output is correct
52 Correct 303 ms 11600 KB Output is correct
53 Correct 208 ms 12624 KB Output is correct
54 Correct 972 ms 13652 KB Output is correct
55 Correct 475 ms 8284 KB Output is correct
56 Correct 471 ms 12116 KB Output is correct
# Verdict Execution time Memory 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 2 ms 460 KB Output is correct
5 Correct 3 ms 344 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 161 ms 6576 KB Output is correct
10 Correct 427 ms 7772 KB Output is correct
11 Correct 637 ms 7772 KB Output is correct
12 Correct 584 ms 8016 KB Output is correct
13 Correct 888 ms 8024 KB Output is correct
14 Execution timed out 2067 ms 6704 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 2 ms 460 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 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 161 ms 6576 KB Output is correct
11 Correct 427 ms 7772 KB Output is correct
12 Correct 637 ms 7772 KB Output is correct
13 Correct 584 ms 8016 KB Output is correct
14 Correct 888 ms 8024 KB Output is correct
15 Execution timed out 2067 ms 6704 KB Time limit exceeded
16 Halted 0 ms 0 KB -