Submission #951519

# Submission time Handle Problem Language Result Execution time Memory
951519 2024-03-22T04:46:01 Z Nhoksocqt1 Swapping Cities (APIO20_swap) C++17
6 / 100
84 ms 17756 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

struct Edge {
    int u, v, w;
} edge[2 * MAXN];

ii minw[3];
vector<ii> adj[MAXN];
int deg[MAXN], wEdge[MAXN], maxw, numNode, numEdge;
bool check_sub1, check_sub2;

void init(int _N, int _M, vector<int> _U, vector<int> _V, vector<int> _W) {
    numNode = _N, numEdge = _M;

    minw[0] = minw[1] = minw[2] = {1e9+7, -1};
    check_sub2 = (numEdge + 1 == numNode);
    for (int i = 0; i < numEdge; ++i) {
        edge[i] = {_U[i], _V[i], _W[i]};
        adj[edge[i].u].push_back(ii(edge[i].v, edge[i].w));
        adj[edge[i].v].push_back(ii(edge[i].u, edge[i].w));
        check_sub2 &= (edge[i].u == 0);
        maxw = max(maxw, edge[i].w);

        wEdge[edge[i].v] = edge[i].w;
        if(minw[0].fi > edge[i].w) {
            minw[2] = minw[1], minw[1] = minw[0];
            minw[0] = {edge[i].w, edge[i].v};
        } else
            if(minw[1].fi > edge[i].w) {
                minw[2] = minw[1];
                minw[1] = {edge[i].w, edge[i].v};
            } else
                if(minw[2].fi > edge[i].w) {
                    minw[2] = {edge[i].w, edge[i].v};
                }
    }

    check_sub1 = 1;
    for (int i = 0; i < numNode; ++i)
        check_sub1 &= (sz(adj[i]) <= 2);

    sort(edge, edge + numEdge, [](const Edge &a, const Edge &b) {
        return (a.w < b.w);
    });
}

int sub2(int x, int y) {
    if(numNode <= 3)
        return -1;

    int res = max(wEdge[x], wEdge[y]);
    for (int k = 0; k < 3; ++k) {
        if(minw[k].se != x && minw[k].se != y) {
            res = max(res, minw[k].fi);
            break;
        }
    }

    return res;
}

int getMinimumFuelCapacity(int x, int y) {
    if(check_sub1)
        return (numNode == numEdge) ? maxw : -1;

    if(check_sub2)
        return sub2(x, y);

    return -1;
}

#ifdef Nhoksocqt1

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "swap"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    vector<int> _U, _V, _W;
    int _N, _M, _Q;
    cin >> _N >> _M >> _Q;

    _U.resize(_M), _V.resize(_M), _W.resize(_M);
    for (int i = 0; i < _M; ++i) {
        cin >> _U[i] >> _V[i] >> _W[i];
    }

    init(_N, _M, _U, _V, _W);
    for (int t = 0; t < _Q; ++t) {
        int _X, _Y;
        cin >> _X >> _Y;
        cout << "MINIMUM FUEL CAPACITY " << _X << ' ' << " TO " << _Y << ": " << getMinimumFuelCapacity(_X, _Y) << '\n';
    }

    return 0;
}

#endif // Nhoksocqt1
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 30 ms 8796 KB Output is correct
10 Correct 49 ms 9872 KB Output is correct
11 Correct 36 ms 9820 KB Output is correct
12 Correct 42 ms 10068 KB Output is correct
13 Correct 37 ms 10072 KB Output is correct
14 Correct 34 ms 9052 KB Output is correct
15 Correct 78 ms 11740 KB Output is correct
16 Correct 77 ms 11524 KB Output is correct
17 Correct 78 ms 12004 KB Output is correct
18 Correct 77 ms 11980 KB Output is correct
19 Correct 40 ms 8788 KB Output is correct
20 Correct 78 ms 12928 KB Output is correct
21 Correct 78 ms 13072 KB Output is correct
22 Correct 84 ms 13188 KB Output is correct
23 Correct 81 ms 13264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 76 ms 13672 KB Output is correct
4 Correct 78 ms 17608 KB Output is correct
5 Incorrect 81 ms 17756 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Incorrect 2 ms 4444 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 30 ms 8796 KB Output is correct
10 Correct 49 ms 9872 KB Output is correct
11 Correct 36 ms 9820 KB Output is correct
12 Correct 42 ms 10068 KB Output is correct
13 Correct 37 ms 10072 KB Output is correct
14 Correct 34 ms 9052 KB Output is correct
15 Correct 78 ms 11740 KB Output is correct
16 Correct 77 ms 11524 KB Output is correct
17 Correct 78 ms 12004 KB Output is correct
18 Correct 77 ms 11980 KB Output is correct
19 Correct 76 ms 13672 KB Output is correct
20 Correct 78 ms 17608 KB Output is correct
21 Incorrect 81 ms 17756 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -