답안 #571189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571189 2022-06-01T12:39:15 Z 2fat2code 자매 도시 (APIO20_swap) C++17
50 / 100
294 ms 58196 KB
#include "swap.h"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(s) s.begin(), s.end()
using namespace std;

const int nmax = 300005;

int pardsu[nmax], last, lca[nmax][20], marked[nmax], grad[nmax], val[nmax], timp, in[nmax], out[nmax], apropiat[nmax], ans[nmax];
vector<pair<int, pair<int,int>>>edges;
vector<int>nod[nmax];

int findpar(int x){
    if(x != pardsu[x]){
        pardsu[x] = findpar(pardsu[x]);
    }
    return pardsu[x];
}

void dfs(int s, int apr, int par = 0){
    in[s] = ++timp;
    if(marked[s]) apr = val[s];
    ans[s] = apr;
    for(auto it : nod[s]){
        if(it != par){
            dfs(it, apr, s);
            ans[s] = min(ans[s], max(val[s], ans[it]));
        }
    }
    out[s] = ++timp;
}

bool is_lca(int x, int y){
    if(in[x] <= in[y] && out[x] >= out[y]) return true;
    else return false;
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    last = N;
    for(int i=1;i<=N;i++) pardsu[i] = i;
    for(int i=0;i<M;i++){
        U[i]++; V[i]++;
        edges.push_back({W[i], {U[i], V[i]}});
    }
    sort(all(edges));
    for(auto it : edges){
        int x = findpar(it.sc.fr);
        int y = findpar(it.sc.sc);
        ++last;
        pardsu[y] = last;
        pardsu[x] = last;
        pardsu[last] = last;
        val[last] = it.fr;
        grad[it.sc.sc]++;
        grad[it.sc.fr]++;
        lca[x][0] = last;
        lca[y][0] = last;
        nod[last].push_back(x);
        if(x != y) nod[last].push_back(y);
        if(x == y){
            marked[last] = 1;
        }
        else{
            if(grad[it.sc.sc] >= 3 || grad[it.sc.fr] >= 3){
                marked[last] = 1;
            }
        }
    }
    for(int i=1;i<=19;i++){
        for(int j=1;j<=last;j++){
            lca[j][i] = lca[lca[j][i-1]][i-1];
        }
    }
    dfs(last, 1e9);
   // for(int i=1;i<=N+M;i++) cout << ans[i] << ' ';
//    cout << '\n';
}

int getMinimumFuelCapacity(int X, int Y) {
    X++;
    Y++;
    int curr;
    if(is_lca(X, Y)) curr = X;
    else if(is_lca(Y, X)) curr = Y;
    else{
        curr = X;
        for(int i=19;i>=0;i--){
            if(lca[curr][i] != 0 && !is_lca(lca[curr][i], Y)) curr = lca[curr][i];
        }
        curr = lca[curr][0];
    }
    if(ans[curr] < 1e9){
        return ans[curr];
    }
    else{
        return -1;
    }
}


/**
6 5
0 1 1
1 2 2
1 3 3
1 4 4
4 5 5
3
0 4
5 4
0 2



*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 5 ms 7572 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 5 ms 7636 KB Output is correct
9 Correct 104 ms 27960 KB Output is correct
10 Correct 119 ms 32628 KB Output is correct
11 Correct 112 ms 32104 KB Output is correct
12 Correct 120 ms 33560 KB Output is correct
13 Correct 107 ms 37400 KB Output is correct
14 Correct 92 ms 27968 KB Output is correct
15 Correct 188 ms 34536 KB Output is correct
16 Correct 189 ms 33764 KB Output is correct
17 Correct 200 ms 35304 KB Output is correct
18 Correct 274 ms 39264 KB Output is correct
19 Correct 71 ms 14952 KB Output is correct
20 Correct 175 ms 35812 KB Output is correct
21 Correct 192 ms 34984 KB Output is correct
22 Correct 206 ms 36780 KB Output is correct
23 Correct 294 ms 40764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 261 ms 42956 KB Output is correct
4 Correct 250 ms 44620 KB Output is correct
5 Correct 246 ms 43696 KB Output is correct
6 Correct 250 ms 44340 KB Output is correct
7 Correct 247 ms 44096 KB Output is correct
8 Correct 265 ms 42672 KB Output is correct
9 Correct 253 ms 43856 KB Output is correct
10 Correct 242 ms 42432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 5 ms 7572 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 5 ms 7636 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7636 KB Output is correct
11 Correct 4 ms 7636 KB Output is correct
12 Correct 4 ms 7636 KB Output is correct
13 Correct 5 ms 7608 KB Output is correct
14 Correct 4 ms 7508 KB Output is correct
15 Correct 4 ms 7636 KB Output is correct
16 Correct 4 ms 7636 KB Output is correct
17 Correct 4 ms 7636 KB Output is correct
18 Correct 4 ms 7636 KB Output is correct
19 Correct 4 ms 7636 KB Output is correct
20 Correct 4 ms 7636 KB Output is correct
21 Correct 5 ms 7712 KB Output is correct
22 Correct 5 ms 7764 KB Output is correct
23 Correct 4 ms 7508 KB Output is correct
24 Correct 5 ms 7764 KB Output is correct
25 Correct 5 ms 7764 KB Output is correct
26 Correct 5 ms 7892 KB Output is correct
27 Correct 4 ms 7636 KB Output is correct
28 Correct 6 ms 7876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7636 KB Output is correct
7 Correct 5 ms 7572 KB Output is correct
8 Correct 5 ms 7636 KB Output is correct
9 Correct 5 ms 7636 KB Output is correct
10 Correct 104 ms 27960 KB Output is correct
11 Correct 119 ms 32628 KB Output is correct
12 Correct 112 ms 32104 KB Output is correct
13 Correct 120 ms 33560 KB Output is correct
14 Correct 107 ms 37400 KB Output is correct
15 Correct 5 ms 7636 KB Output is correct
16 Correct 4 ms 7636 KB Output is correct
17 Correct 4 ms 7636 KB Output is correct
18 Correct 5 ms 7608 KB Output is correct
19 Correct 4 ms 7508 KB Output is correct
20 Correct 4 ms 7636 KB Output is correct
21 Correct 4 ms 7636 KB Output is correct
22 Correct 4 ms 7636 KB Output is correct
23 Correct 4 ms 7636 KB Output is correct
24 Correct 4 ms 7636 KB Output is correct
25 Correct 4 ms 7636 KB Output is correct
26 Correct 5 ms 7712 KB Output is correct
27 Correct 5 ms 7764 KB Output is correct
28 Correct 4 ms 7508 KB Output is correct
29 Correct 5 ms 7764 KB Output is correct
30 Correct 5 ms 7764 KB Output is correct
31 Correct 5 ms 7892 KB Output is correct
32 Correct 4 ms 7636 KB Output is correct
33 Correct 6 ms 7876 KB Output is correct
34 Correct 17 ms 11028 KB Output is correct
35 Correct 128 ms 33504 KB Output is correct
36 Correct 121 ms 33596 KB Output is correct
37 Correct 117 ms 33712 KB Output is correct
38 Correct 114 ms 33560 KB Output is correct
39 Correct 132 ms 33456 KB Output is correct
40 Correct 104 ms 31300 KB Output is correct
41 Correct 114 ms 33608 KB Output is correct
42 Correct 114 ms 33608 KB Output is correct
43 Correct 114 ms 38820 KB Output is correct
44 Correct 123 ms 34028 KB Output is correct
45 Correct 155 ms 47048 KB Output is correct
46 Correct 114 ms 33612 KB Output is correct
47 Correct 119 ms 34112 KB Output is correct
48 Correct 144 ms 38516 KB Output is correct
49 Correct 113 ms 46380 KB Output is correct
50 Correct 110 ms 37440 KB Output is correct
51 Correct 140 ms 41772 KB Output is correct
52 Correct 183 ms 48636 KB Output is correct
53 Correct 206 ms 51636 KB Output is correct
54 Correct 216 ms 58196 KB Output is correct
55 Correct 120 ms 38296 KB Output is correct
56 Correct 183 ms 54020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 5 ms 7572 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 5 ms 7636 KB Output is correct
9 Correct 104 ms 27960 KB Output is correct
10 Correct 119 ms 32628 KB Output is correct
11 Correct 112 ms 32104 KB Output is correct
12 Correct 120 ms 33560 KB Output is correct
13 Correct 107 ms 37400 KB Output is correct
14 Correct 92 ms 27968 KB Output is correct
15 Correct 188 ms 34536 KB Output is correct
16 Correct 189 ms 33764 KB Output is correct
17 Correct 200 ms 35304 KB Output is correct
18 Correct 274 ms 39264 KB Output is correct
19 Correct 261 ms 42956 KB Output is correct
20 Correct 250 ms 44620 KB Output is correct
21 Correct 246 ms 43696 KB Output is correct
22 Correct 250 ms 44340 KB Output is correct
23 Correct 247 ms 44096 KB Output is correct
24 Correct 265 ms 42672 KB Output is correct
25 Correct 253 ms 43856 KB Output is correct
26 Correct 242 ms 42432 KB Output is correct
27 Correct 5 ms 7636 KB Output is correct
28 Correct 4 ms 7636 KB Output is correct
29 Correct 4 ms 7636 KB Output is correct
30 Correct 5 ms 7608 KB Output is correct
31 Correct 4 ms 7508 KB Output is correct
32 Correct 4 ms 7636 KB Output is correct
33 Correct 4 ms 7636 KB Output is correct
34 Correct 4 ms 7636 KB Output is correct
35 Correct 4 ms 7636 KB Output is correct
36 Correct 17 ms 11028 KB Output is correct
37 Correct 128 ms 33504 KB Output is correct
38 Correct 121 ms 33596 KB Output is correct
39 Correct 117 ms 33712 KB Output is correct
40 Correct 114 ms 33560 KB Output is correct
41 Correct 132 ms 33456 KB Output is correct
42 Correct 104 ms 31300 KB Output is correct
43 Correct 114 ms 33608 KB Output is correct
44 Correct 114 ms 33608 KB Output is correct
45 Correct 114 ms 38820 KB Output is correct
46 Correct 123 ms 34028 KB Output is correct
47 Correct 26 ms 10948 KB Output is correct
48 Incorrect 211 ms 36000 KB Output isn't correct
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7636 KB Output is correct
7 Correct 5 ms 7572 KB Output is correct
8 Correct 5 ms 7636 KB Output is correct
9 Correct 5 ms 7636 KB Output is correct
10 Correct 104 ms 27960 KB Output is correct
11 Correct 119 ms 32628 KB Output is correct
12 Correct 112 ms 32104 KB Output is correct
13 Correct 120 ms 33560 KB Output is correct
14 Correct 107 ms 37400 KB Output is correct
15 Correct 92 ms 27968 KB Output is correct
16 Correct 188 ms 34536 KB Output is correct
17 Correct 189 ms 33764 KB Output is correct
18 Correct 200 ms 35304 KB Output is correct
19 Correct 274 ms 39264 KB Output is correct
20 Correct 261 ms 42956 KB Output is correct
21 Correct 250 ms 44620 KB Output is correct
22 Correct 246 ms 43696 KB Output is correct
23 Correct 250 ms 44340 KB Output is correct
24 Correct 247 ms 44096 KB Output is correct
25 Correct 265 ms 42672 KB Output is correct
26 Correct 253 ms 43856 KB Output is correct
27 Correct 242 ms 42432 KB Output is correct
28 Correct 5 ms 7636 KB Output is correct
29 Correct 4 ms 7636 KB Output is correct
30 Correct 4 ms 7636 KB Output is correct
31 Correct 5 ms 7608 KB Output is correct
32 Correct 4 ms 7508 KB Output is correct
33 Correct 4 ms 7636 KB Output is correct
34 Correct 4 ms 7636 KB Output is correct
35 Correct 4 ms 7636 KB Output is correct
36 Correct 4 ms 7636 KB Output is correct
37 Correct 17 ms 11028 KB Output is correct
38 Correct 128 ms 33504 KB Output is correct
39 Correct 121 ms 33596 KB Output is correct
40 Correct 117 ms 33712 KB Output is correct
41 Correct 114 ms 33560 KB Output is correct
42 Correct 132 ms 33456 KB Output is correct
43 Correct 104 ms 31300 KB Output is correct
44 Correct 114 ms 33608 KB Output is correct
45 Correct 114 ms 33608 KB Output is correct
46 Correct 114 ms 38820 KB Output is correct
47 Correct 123 ms 34028 KB Output is correct
48 Correct 26 ms 10948 KB Output is correct
49 Incorrect 211 ms 36000 KB Output isn't correct
50 Halted 0 ms 0 KB -