답안 #951521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951521 2024-03-22T04:49:34 Z Nhoksocqt1 자매 도시 (APIO20_swap) C++17
13 / 100
92 ms 17992 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]), cnt(1 + (x == 0));
    for (int k = 0; k < 3; ++k) {
        if(minw[k].se != x && minw[k].se != y) {
            if(--cnt == 0) {
                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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 31 ms 8824 KB Output is correct
10 Correct 38 ms 9820 KB Output is correct
11 Correct 39 ms 9900 KB Output is correct
12 Correct 40 ms 10064 KB Output is correct
13 Correct 40 ms 10076 KB Output is correct
14 Correct 37 ms 9160 KB Output is correct
15 Correct 80 ms 11760 KB Output is correct
16 Correct 78 ms 11532 KB Output is correct
17 Correct 85 ms 12124 KB Output is correct
18 Correct 81 ms 11964 KB Output is correct
19 Correct 43 ms 8796 KB Output is correct
20 Correct 80 ms 12904 KB Output is correct
21 Correct 84 ms 13028 KB Output is correct
22 Correct 84 ms 13260 KB Output is correct
23 Correct 87 ms 13240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 77 ms 13636 KB Output is correct
4 Correct 80 ms 13788 KB Output is correct
5 Correct 78 ms 13912 KB Output is correct
6 Correct 81 ms 17452 KB Output is correct
7 Correct 92 ms 17992 KB Output is correct
8 Correct 79 ms 17456 KB Output is correct
9 Correct 78 ms 17644 KB Output is correct
10 Correct 79 ms 17324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Incorrect 1 ms 4444 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 31 ms 8824 KB Output is correct
10 Correct 38 ms 9820 KB Output is correct
11 Correct 39 ms 9900 KB Output is correct
12 Correct 40 ms 10064 KB Output is correct
13 Correct 40 ms 10076 KB Output is correct
14 Correct 37 ms 9160 KB Output is correct
15 Correct 80 ms 11760 KB Output is correct
16 Correct 78 ms 11532 KB Output is correct
17 Correct 85 ms 12124 KB Output is correct
18 Correct 81 ms 11964 KB Output is correct
19 Correct 77 ms 13636 KB Output is correct
20 Correct 80 ms 13788 KB Output is correct
21 Correct 78 ms 13912 KB Output is correct
22 Correct 81 ms 17452 KB Output is correct
23 Correct 92 ms 17992 KB Output is correct
24 Correct 79 ms 17456 KB Output is correct
25 Correct 78 ms 17644 KB Output is correct
26 Correct 79 ms 17324 KB Output is correct
27 Incorrect 1 ms 4444 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -