Submission #385171

# Submission time Handle Problem Language Result Execution time Memory
385171 2021-04-03T12:45:23 Z kwongweng Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 13660 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second

vector<pair<int, ii>> edges;
vi p, r, deg, maxi, num, sz;
void init(int n, int m, vi U, vi V, vi W) {
    FOR(i, 0, m){
        edges.pb({W[i], {U[i], V[i]}});
    }
    sort(edges.begin(), edges.end());
    p.resize(n);
    r.resize(n);
    deg.resize(n);
    maxi.resize(n);
    num.resize(n);
    sz.resize(n);
}

int get(int a){
    return p[a] = (p[a] == a ? a : get(p[a]));
}

void Union(int c, int d){
    int a = get(c), b = get(d);
    if (a == b) return;
    if (r[a] == r[b]) r[a]++;
    if (r[a] > r[b]){
        p[b] = a;
        maxi[a] = max(maxi[b], maxi[a]);
        num[a] += num[b];
        sz[a] += sz[b];
    }else{
        p[a] = b;
        maxi[b] = max(maxi[a], maxi[b]);
        num[b] += num[a];
        sz[b] += sz[a];
    }
}


int getMinimumFuelCapacity(int x, int y) {
    FOR(i, 0, p.size()) p[i] = i;
    FOR(i, 0, r.size()){
        r[i] = 0; deg[i] = 0, maxi[i] = 0; num[i] = 0; sz[i] = 1;
    }
    FOR(i, 0, edges.size()){
        int a = edges[i].S.F, b = edges[i].S.S;
        Union(a, b);
        deg[a]++; deg[b]++;
        maxi[get(a)] = max(maxi[get(a)], deg[a]);
        maxi[get(b)] = max(maxi[get(b)], deg[b]);
        num[get(a)]++;
        if (get(x) != get(y)) continue;
        if (maxi[get(x)] < 3 && num[get(x)] < sz[get(x)]) continue;
        return edges[i].F;
    }
    return -1;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:8:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
   53 |     FOR(i, 0, p.size()) p[i] = i;
      |         ~~~~~~~~~~~~~~                 
swap.cpp:53:5: note: in expansion of macro 'FOR'
   53 |     FOR(i, 0, p.size()) p[i] = i;
      |     ^~~
swap.cpp:8:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
   54 |     FOR(i, 0, r.size()){
      |         ~~~~~~~~~~~~~~                 
swap.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i, 0, r.size()){
      |     ^~~
swap.cpp:8:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
   57 |     FOR(i, 0, edges.size()){
      |         ~~~~~~~~~~~~~~~~~~             
swap.cpp:57:5: note: in expansion of macro 'FOR'
   57 |     FOR(i, 0, edges.size()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 60 ms 6624 KB Output is correct
10 Correct 94 ms 8032 KB Output is correct
11 Correct 105 ms 7904 KB Output is correct
12 Correct 111 ms 8288 KB Output is correct
13 Correct 126 ms 8416 KB Output is correct
14 Execution timed out 2081 ms 7008 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 2086 ms 11232 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 60 ms 6624 KB Output is correct
11 Correct 94 ms 8032 KB Output is correct
12 Correct 105 ms 7904 KB Output is correct
13 Correct 111 ms 8288 KB Output is correct
14 Correct 126 ms 8416 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 3 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 3 ms 492 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 3 ms 492 KB Output is correct
34 Correct 8 ms 1452 KB Output is correct
35 Correct 115 ms 8032 KB Output is correct
36 Correct 106 ms 8032 KB Output is correct
37 Correct 112 ms 8032 KB Output is correct
38 Correct 112 ms 7904 KB Output is correct
39 Correct 108 ms 7904 KB Output is correct
40 Correct 103 ms 7392 KB Output is correct
41 Correct 130 ms 8288 KB Output is correct
42 Correct 113 ms 8032 KB Output is correct
43 Correct 83 ms 8032 KB Output is correct
44 Correct 115 ms 8416 KB Output is correct
45 Correct 115 ms 10532 KB Output is correct
46 Correct 113 ms 8032 KB Output is correct
47 Correct 106 ms 8032 KB Output is correct
48 Correct 99 ms 8544 KB Output is correct
49 Correct 70 ms 10080 KB Output is correct
50 Correct 57 ms 7140 KB Output is correct
51 Correct 91 ms 9052 KB Output is correct
52 Correct 140 ms 11740 KB Output is correct
53 Correct 152 ms 12760 KB Output is correct
54 Correct 169 ms 13660 KB Output is correct
55 Correct 113 ms 8032 KB Output is correct
56 Correct 150 ms 12380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 60 ms 6624 KB Output is correct
10 Correct 94 ms 8032 KB Output is correct
11 Correct 105 ms 7904 KB Output is correct
12 Correct 111 ms 8288 KB Output is correct
13 Correct 126 ms 8416 KB Output is correct
14 Execution timed out 2081 ms 7008 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 60 ms 6624 KB Output is correct
11 Correct 94 ms 8032 KB Output is correct
12 Correct 105 ms 7904 KB Output is correct
13 Correct 111 ms 8288 KB Output is correct
14 Correct 126 ms 8416 KB Output is correct
15 Execution timed out 2081 ms 7008 KB Time limit exceeded
16 Halted 0 ms 0 KB -