Submission #551816

# Submission time Handle Problem Language Result Execution time Memory
551816 2022-04-21T15:43:25 Z nicolaalexandra Swapping Cities (APIO20_swap) C++14
43 / 100
2000 ms 22232 KB
#include <bits/stdc++.h>
#include "swap.h"
#define DIM 200010
#define INF 2000000000
using namespace std;

struct muchie{
    int x,y,cost;
} mch[DIM];

vector<pair <int,int> > L[DIM];
int t[DIM],ok[DIM],g[DIM];
int n,m,subtask,maxi;

inline int cmp (muchie a, muchie b){
    return a.cost < b.cost;
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {

    n = N, m = M;
    for (int i=0;i<m;i++){
        int x = U[i], y = V[i], cost = W[i];
        x++, y++;

        L[x].push_back(make_pair(y,cost));
        L[y].push_back(make_pair(x,cost));
        maxi = max (maxi,cost);

        mch[i+1] = {x,y,cost};
    }

    subtask = 1;
    for (int i=1;i<=n;i++)
        if (L[i].size() > 2)
            subtask = 0;

    sort (mch+1,mch+m+1,cmp);

}


inline int get_rad (int x){
    while (t[x] > 0)
        x = t[x];
    return x;
}


int getMinimumFuelCapacity(int X, int Y) {

    if (subtask == 1){
        if (m == n-1)
            return -1;
        else return maxi;
    }

    X++, Y++;

    for (int i=1;i<=n;i++){
        t[i] = -1;
        ok[i] = g[i] = 0;
    }

    for (int i=1;i<=m;i++){

        int x = mch[i].x, y = mch[i].y;
        int radx = get_rad(x), rady = get_rad(y);

        if (radx != rady){
            if (t[radx] > t[rady])
                swap (radx, rady);

            ok[radx] |= ok[rady];
            t[radx] += t[rady];
            t[rady] = radx;

            g[x]++, g[y]++;
            if (g[x] >= 3 || g[y] >= 3)
                ok[radx] = 1;
        } else {
            /// o sa am un ciclu in componenta asta
            ok[radx] = 1;
        }


        if (get_rad(X) == get_rad(Y) && ok[get_rad(X)])
            return mch[i].cost;
    }


    return -1;
}
/*
int main (){

    FILE *fin = fopen ("date.in", "r");
    FILE *fout = fopen ("date.out", "w");

    int N, M;
    assert(2 == fscanf(fin, "%d %d", &N, &M));

    std::vector<int> U(M), V(M), W(M);
    for (int i = 0; i < M; ++i) {
        assert(3 == fscanf(fin, "%d %d %d", &U[i], &V[i], &W[i]));
    }

    int Q;
    assert(1 == fscanf(fin,"%d", &Q));

    std::vector<int> X(Q), Y(Q);
    for (int i = 0; i < Q; ++i) {
        assert(2 == fscanf(fin,"%d %d", &X[i], &Y[i]));
    }

    init(N, M, U, V, W);

    std::vector<int> minimum_fuel_capacities(Q);
    for (int i = 0; i < Q; ++i) {
        minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
    }

    for (int i = 0; i < Q; ++i) {
        fprintf(fout, "%d\n", minimum_fuel_capacities[i]);
    }



    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 51 ms 11084 KB Output is correct
10 Correct 83 ms 12156 KB Output is correct
11 Correct 64 ms 12052 KB Output is correct
12 Correct 81 ms 12360 KB Output is correct
13 Correct 65 ms 12348 KB Output is correct
14 Correct 70 ms 11096 KB Output is correct
15 Correct 120 ms 14088 KB Output is correct
16 Correct 128 ms 14012 KB Output is correct
17 Correct 123 ms 14260 KB Output is correct
18 Correct 129 ms 14204 KB Output is correct
19 Correct 62 ms 10304 KB Output is correct
20 Correct 119 ms 15228 KB Output is correct
21 Correct 123 ms 15268 KB Output is correct
22 Correct 119 ms 15636 KB Output is correct
23 Correct 129 ms 15756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Execution timed out 2033 ms 15084 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 4 ms 5040 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 4 ms 5020 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5024 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5152 KB Output is correct
26 Correct 4 ms 5204 KB Output is correct
27 Correct 5 ms 5016 KB Output is correct
28 Correct 4 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5012 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 5016 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5024 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 51 ms 11084 KB Output is correct
11 Correct 83 ms 12156 KB Output is correct
12 Correct 64 ms 12052 KB Output is correct
13 Correct 81 ms 12360 KB Output is correct
14 Correct 65 ms 12348 KB Output is correct
15 Correct 4 ms 5040 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 5 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 4 ms 5040 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5020 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 4 ms 5024 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 4 ms 5152 KB Output is correct
31 Correct 4 ms 5204 KB Output is correct
32 Correct 5 ms 5016 KB Output is correct
33 Correct 4 ms 5204 KB Output is correct
34 Correct 11 ms 6300 KB Output is correct
35 Correct 88 ms 13492 KB Output is correct
36 Correct 72 ms 13472 KB Output is correct
37 Correct 78 ms 13428 KB Output is correct
38 Correct 77 ms 13324 KB Output is correct
39 Correct 70 ms 13316 KB Output is correct
40 Correct 66 ms 12928 KB Output is correct
41 Correct 74 ms 13720 KB Output is correct
42 Correct 78 ms 13472 KB Output is correct
43 Correct 70 ms 13468 KB Output is correct
44 Correct 71 ms 14224 KB Output is correct
45 Correct 94 ms 17852 KB Output is correct
46 Correct 81 ms 13452 KB Output is correct
47 Correct 78 ms 13468 KB Output is correct
48 Correct 81 ms 14352 KB Output is correct
49 Correct 65 ms 18252 KB Output is correct
50 Correct 56 ms 14864 KB Output is correct
51 Correct 97 ms 16236 KB Output is correct
52 Correct 164 ms 19432 KB Output is correct
53 Correct 119 ms 20644 KB Output is correct
54 Correct 123 ms 22232 KB Output is correct
55 Correct 67 ms 13412 KB Output is correct
56 Correct 157 ms 20188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 4 ms 5024 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 51 ms 11084 KB Output is correct
10 Correct 83 ms 12156 KB Output is correct
11 Correct 64 ms 12052 KB Output is correct
12 Correct 81 ms 12360 KB Output is correct
13 Correct 65 ms 12348 KB Output is correct
14 Correct 70 ms 11096 KB Output is correct
15 Correct 120 ms 14088 KB Output is correct
16 Correct 128 ms 14012 KB Output is correct
17 Correct 123 ms 14260 KB Output is correct
18 Correct 129 ms 14204 KB Output is correct
19 Execution timed out 2033 ms 15084 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5012 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 5016 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5024 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 51 ms 11084 KB Output is correct
11 Correct 83 ms 12156 KB Output is correct
12 Correct 64 ms 12052 KB Output is correct
13 Correct 81 ms 12360 KB Output is correct
14 Correct 65 ms 12348 KB Output is correct
15 Correct 70 ms 11096 KB Output is correct
16 Correct 120 ms 14088 KB Output is correct
17 Correct 128 ms 14012 KB Output is correct
18 Correct 123 ms 14260 KB Output is correct
19 Correct 129 ms 14204 KB Output is correct
20 Execution timed out 2033 ms 15084 KB Time limit exceeded
21 Halted 0 ms 0 KB -