Submission #336158

# Submission time Handle Problem Language Result Execution time Memory
336158 2020-12-14T22:50:10 Z duality Swapping Cities (APIO20_swap) C++11
100 / 100
312 ms 17252 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int m;
struct edge { int u,v,w; };
bool comp(edge a,edge b) {
    return a.w < b.w;
}
edge edges[200000];
int deg[100000];
int parent[100000],r[100000],parentt[100000],goodt[100000];
int find(int n) {
    if (parent[n] == n) return n;
    else return find(parent[n]);
}
void init(int N,int M,vector<int> U,vector<int> V,vector<int> W) {
    int i;
    m = M;
    for (i = 0; i < M; i++) edges[i] = (edge){U[i],V[i],W[i]};
    sort(edges,edges+M,comp);
    for (i = 0; i < N; i++) parent[i] = i,r[i] = 1,parentt[i] = goodt[i] = M;
    for (i = 0; i < M; i++) {
        int u = find(edges[i].u),v = find(edges[i].v);
        deg[edges[i].u]++,deg[edges[i].v]++;
        if (u != v) {
            if (r[u] > r[v]) swap(u,v);
            parent[u] = v,parentt[u] = i;
            if (goodt[u] < M) goodt[v] = min(goodt[v],i);
            if (r[u] == r[v]) r[v]++;
        }
        if ((u == v) || (deg[edges[i].u] >= 3) || (deg[edges[i].v] >= 3)) goodt[v] = min(goodt[v],i);
    }
}
int getMinimumFuelCapacity(int X,int Y) {
    int l = 0,r = m;
    while (l < r) {
        int mid = (l+r) / 2;
        int u = X,v = Y;
        while (parentt[u] <= mid) u = parent[u];
        while (parentt[v] <= mid) v = parent[v];
        if ((u == v) && (goodt[u] <= mid)) r = mid;
        else l = mid+1;
    }
    return (l == m) ? -1:edges[l].w;
}
# 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 40 ms 6252 KB Output is correct
10 Correct 51 ms 7660 KB Output is correct
11 Correct 49 ms 7532 KB Output is correct
12 Correct 55 ms 8044 KB Output is correct
13 Correct 51 ms 8044 KB Output is correct
14 Correct 55 ms 6636 KB Output is correct
15 Correct 203 ms 11832 KB Output is correct
16 Correct 205 ms 11672 KB Output is correct
17 Correct 207 ms 12004 KB Output is correct
18 Correct 136 ms 12112 KB Output is correct
19 Correct 117 ms 6580 KB Output is correct
20 Correct 199 ms 12776 KB Output is correct
21 Correct 241 ms 13092 KB Output is correct
22 Correct 222 ms 13520 KB Output is correct
23 Correct 137 ms 13520 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 143 ms 12428 KB Output is correct
4 Correct 142 ms 12772 KB Output is correct
5 Correct 146 ms 12800 KB Output is correct
6 Correct 146 ms 12368 KB Output is correct
7 Correct 147 ms 12776 KB Output is correct
8 Correct 156 ms 12440 KB Output is correct
9 Correct 142 ms 12520 KB Output is correct
10 Correct 146 ms 12452 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 40 ms 6252 KB Output is correct
11 Correct 51 ms 7660 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 55 ms 8044 KB Output is correct
14 Correct 51 ms 8044 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 7 ms 1388 KB Output is correct
25 Correct 54 ms 7676 KB Output is correct
26 Correct 51 ms 7660 KB Output is correct
27 Correct 52 ms 7660 KB Output is correct
28 Correct 48 ms 7536 KB Output is correct
29 Correct 48 ms 7532 KB Output is correct
30 Correct 43 ms 6892 KB Output is correct
31 Correct 67 ms 8044 KB Output is correct
32 Correct 71 ms 7660 KB Output is correct
33 Correct 76 ms 7660 KB Output is correct
34 Correct 53 ms 7916 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 492 KB Output is correct
45 Correct 78 ms 10220 KB Output is correct
46 Correct 49 ms 7660 KB Output is correct
47 Correct 58 ms 7660 KB Output is correct
48 Correct 58 ms 8172 KB Output is correct
49 Correct 87 ms 8684 KB Output is correct
50 Correct 61 ms 7020 KB Output is correct
51 Correct 70 ms 8812 KB Output is correct
52 Correct 93 ms 11372 KB Output is correct
53 Correct 97 ms 12396 KB Output is correct
54 Correct 115 ms 13324 KB Output is correct
55 Correct 50 ms 7788 KB Output is correct
56 Correct 107 ms 12016 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 40 ms 6252 KB Output is correct
10 Correct 51 ms 7660 KB Output is correct
11 Correct 49 ms 7532 KB Output is correct
12 Correct 55 ms 8044 KB Output is correct
13 Correct 51 ms 8044 KB Output is correct
14 Correct 55 ms 6636 KB Output is correct
15 Correct 203 ms 11832 KB Output is correct
16 Correct 205 ms 11672 KB Output is correct
17 Correct 207 ms 12004 KB Output is correct
18 Correct 136 ms 12112 KB Output is correct
19 Correct 143 ms 12428 KB Output is correct
20 Correct 142 ms 12772 KB Output is correct
21 Correct 146 ms 12800 KB Output is correct
22 Correct 146 ms 12368 KB Output is correct
23 Correct 147 ms 12776 KB Output is correct
24 Correct 156 ms 12440 KB Output is correct
25 Correct 142 ms 12520 KB Output is correct
26 Correct 146 ms 12452 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 7 ms 1388 KB Output is correct
37 Correct 54 ms 7676 KB Output is correct
38 Correct 51 ms 7660 KB Output is correct
39 Correct 52 ms 7660 KB Output is correct
40 Correct 48 ms 7536 KB Output is correct
41 Correct 48 ms 7532 KB Output is correct
42 Correct 43 ms 6892 KB Output is correct
43 Correct 67 ms 8044 KB Output is correct
44 Correct 71 ms 7660 KB Output is correct
45 Correct 76 ms 7660 KB Output is correct
46 Correct 53 ms 7916 KB Output is correct
47 Correct 20 ms 1884 KB Output is correct
48 Correct 219 ms 12520 KB Output is correct
49 Correct 208 ms 12624 KB Output is correct
50 Correct 234 ms 12584 KB Output is correct
51 Correct 205 ms 12508 KB Output is correct
52 Correct 204 ms 12184 KB Output is correct
53 Correct 194 ms 11232 KB Output is correct
54 Correct 221 ms 13484 KB Output is correct
55 Correct 220 ms 12496 KB Output is correct
56 Correct 146 ms 12496 KB Output is correct
57 Correct 210 ms 13392 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 40 ms 6252 KB Output is correct
11 Correct 51 ms 7660 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 55 ms 8044 KB Output is correct
14 Correct 51 ms 8044 KB Output is correct
15 Correct 55 ms 6636 KB Output is correct
16 Correct 203 ms 11832 KB Output is correct
17 Correct 205 ms 11672 KB Output is correct
18 Correct 207 ms 12004 KB Output is correct
19 Correct 136 ms 12112 KB Output is correct
20 Correct 143 ms 12428 KB Output is correct
21 Correct 142 ms 12772 KB Output is correct
22 Correct 146 ms 12800 KB Output is correct
23 Correct 146 ms 12368 KB Output is correct
24 Correct 147 ms 12776 KB Output is correct
25 Correct 156 ms 12440 KB Output is correct
26 Correct 142 ms 12520 KB Output is correct
27 Correct 146 ms 12452 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 7 ms 1388 KB Output is correct
38 Correct 54 ms 7676 KB Output is correct
39 Correct 51 ms 7660 KB Output is correct
40 Correct 52 ms 7660 KB Output is correct
41 Correct 48 ms 7536 KB Output is correct
42 Correct 48 ms 7532 KB Output is correct
43 Correct 43 ms 6892 KB Output is correct
44 Correct 67 ms 8044 KB Output is correct
45 Correct 71 ms 7660 KB Output is correct
46 Correct 76 ms 7660 KB Output is correct
47 Correct 53 ms 7916 KB Output is correct
48 Correct 20 ms 1884 KB Output is correct
49 Correct 219 ms 12520 KB Output is correct
50 Correct 208 ms 12624 KB Output is correct
51 Correct 234 ms 12584 KB Output is correct
52 Correct 205 ms 12508 KB Output is correct
53 Correct 204 ms 12184 KB Output is correct
54 Correct 194 ms 11232 KB Output is correct
55 Correct 221 ms 13484 KB Output is correct
56 Correct 220 ms 12496 KB Output is correct
57 Correct 146 ms 12496 KB Output is correct
58 Correct 210 ms 13392 KB Output is correct
59 Correct 117 ms 6580 KB Output is correct
60 Correct 199 ms 12776 KB Output is correct
61 Correct 241 ms 13092 KB Output is correct
62 Correct 222 ms 13520 KB Output is correct
63 Correct 137 ms 13520 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 492 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 1 ms 492 KB Output is correct
71 Correct 2 ms 492 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 492 KB Output is correct
74 Correct 78 ms 10220 KB Output is correct
75 Correct 49 ms 7660 KB Output is correct
76 Correct 58 ms 7660 KB Output is correct
77 Correct 58 ms 8172 KB Output is correct
78 Correct 87 ms 8684 KB Output is correct
79 Correct 61 ms 7020 KB Output is correct
80 Correct 70 ms 8812 KB Output is correct
81 Correct 93 ms 11372 KB Output is correct
82 Correct 97 ms 12396 KB Output is correct
83 Correct 115 ms 13324 KB Output is correct
84 Correct 50 ms 7788 KB Output is correct
85 Correct 107 ms 12016 KB Output is correct
86 Correct 59 ms 4912 KB Output is correct
87 Correct 220 ms 12496 KB Output is correct
88 Correct 212 ms 12624 KB Output is correct
89 Correct 198 ms 12608 KB Output is correct
90 Correct 206 ms 13124 KB Output is correct
91 Correct 190 ms 13084 KB Output is correct
92 Correct 199 ms 13640 KB Output is correct
93 Correct 309 ms 16040 KB Output is correct
94 Correct 237 ms 16928 KB Output is correct
95 Correct 312 ms 17252 KB Output is correct
96 Correct 146 ms 12624 KB Output is correct
97 Correct 226 ms 15020 KB Output is correct