Submission #981690

# Submission time Handle Problem Language Result Execution time Memory
981690 2024-05-13T13:01:36 Z Alkaser_ID Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 13512 KB
#include "swap.h"
using namespace std;
#include <bits/stdc++.h>

int n,m;
vector<pair<int,pair<int,int>>> v;
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    n=N;m = M;
    for(int i=0;i<m;++i){
        v.push_back({W[i],{U[i],V[i]}});
    }
    sort(v.begin(),v.end());
}
int p[100005],sz[100005],dg[100005]; bool bl[100005];
inline int parent(int a){
    if(a == p[a]) return a;
    return a = parent(p[a]);
}

inline void merg(int x,int y){
    int a = parent(x),b = parent(y);
    if(a == b) return;
    if(sz[b] > sz[a]) swap(a,b);
    sz[a] += sz[b];
    p[b] = a;
    bl[a] = bl[a] | bl[b];
}

int getMinimumFuelCapacity(int X, int Y) {
    for(int i=0;i<n;++i) {
        p[i] = i; sz[i] = 1;
        dg[i] = 0;
        bl[i] = false;
    }
    int res = -1;
    for(int i=0;i<m;++i){
        int vl = v[i].first;
        int u = v[i].second.first, d = v[i].second.second;
        dg[u]++;dg[d]++;
        int U = parent(u),D = parent(d);
        if(dg[u] > 2) bl[U] = true;
        if(dg[d] > 2) bl[D] = true;
        if(U == D) bl[U] = true;
        else merg(U,D);
        int px = parent(X),py = parent(Y);
        if(px == py && bl[px]) {
            res = vl;
            break;
        }
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 28 ms 3804 KB Output is correct
10 Correct 41 ms 4252 KB Output is correct
11 Correct 40 ms 4308 KB Output is correct
12 Correct 42 ms 4292 KB Output is correct
13 Correct 39 ms 4296 KB Output is correct
14 Execution timed out 2041 ms 4036 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 0 ms 344 KB Output is correct
3 Execution timed out 2039 ms 5996 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 28 ms 3804 KB Output is correct
11 Correct 41 ms 4252 KB Output is correct
12 Correct 40 ms 4308 KB Output is correct
13 Correct 42 ms 4292 KB Output is correct
14 Correct 39 ms 4296 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 504 KB Output is correct
34 Correct 5 ms 1416 KB Output is correct
35 Correct 41 ms 6092 KB Output is correct
36 Correct 42 ms 6100 KB Output is correct
37 Correct 41 ms 6092 KB Output is correct
38 Correct 40 ms 6100 KB Output is correct
39 Correct 47 ms 6088 KB Output is correct
40 Correct 40 ms 5844 KB Output is correct
41 Correct 43 ms 6356 KB Output is correct
42 Correct 41 ms 6088 KB Output is correct
43 Correct 35 ms 6100 KB Output is correct
44 Correct 46 ms 6452 KB Output is correct
45 Correct 59 ms 10180 KB Output is correct
46 Correct 41 ms 6096 KB Output is correct
47 Correct 41 ms 6088 KB Output is correct
48 Correct 47 ms 6608 KB Output is correct
49 Correct 50 ms 9928 KB Output is correct
50 Correct 42 ms 7372 KB Output is correct
51 Correct 49 ms 7692 KB Output is correct
52 Correct 63 ms 11976 KB Output is correct
53 Correct 66 ms 11592 KB Output is correct
54 Correct 74 ms 13512 KB Output is correct
55 Correct 36 ms 6080 KB Output is correct
56 Correct 72 ms 11716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 28 ms 3804 KB Output is correct
10 Correct 41 ms 4252 KB Output is correct
11 Correct 40 ms 4308 KB Output is correct
12 Correct 42 ms 4292 KB Output is correct
13 Correct 39 ms 4296 KB Output is correct
14 Execution timed out 2041 ms 4036 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 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 28 ms 3804 KB Output is correct
11 Correct 41 ms 4252 KB Output is correct
12 Correct 40 ms 4308 KB Output is correct
13 Correct 42 ms 4292 KB Output is correct
14 Correct 39 ms 4296 KB Output is correct
15 Execution timed out 2041 ms 4036 KB Time limit exceeded
16 Halted 0 ms 0 KB -