답안 #467207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467207 2021-08-22T03:29:05 Z SirCovidThe19th 자매 도시 (APIO20_swap) C++17
6 / 100
433 ms 45464 KB
#include <bits/stdc++.h>
using namespace std; 

const int mx = 3e5 + 5;

int node, par[mx], up[mx][19], vals[mx], dep[mx]; bool ok[mx][19], cyc[mx]; 
vector<int> adj[mx];

int get(int i){
    return i == par[i] ? i : par[i] = get(par[i]);
}
void merge(int a, int b){
    a = get(a); b = get(b);
    cyc[node] = (a == b) or cyc[a] or cyc[b];
    adj[node].push_back(a); if (a != b) adj[node].push_back(b);
    par[a] = par[b] = node++;
}
void dfs(int i){
    for (int l = 1; l < 19; l++){
        up[i][l] = up[up[i][l - 1]][l - 1];
        ok[i][l] = ok[up[i][l - 1]][l - 1] | ok[i][l - 1];
    }
    for (auto x : adj[i]){
        up[x][0] = i; ok[x][0] = cyc[i];
        dep[x] = dep[i] + 1; dfs(x);
    }
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w){
    int idx[m]; node = n + 1; iota(idx, idx + m, 0); iota(par, par + n + m + 1, 0); 
    sort(idx, idx + m, [&](int a, int b){ return w[a] < w[b]; });
    for (int i : idx){
        vals[node] = w[i]; 
        merge(u[i] + 1, v[i] + 1);
    }
    for (int i = n + m; i > 0; i--) 
        if (!up[i][0]) dfs(i); 
}
int getMinimumFuelCapacity(int x, int y){
    x++; y++; if (dep[x] < dep[y]) swap(x, y);
    for (int i = 18; i >= 0; i--)
        if (((dep[x] - dep[y]) >> i) & 1) x = up[x][i];
    for (int i = 18; i >= 0; i--)
        if (up[x][i] != up[y][i] or (!ok[x][i] and !ok[y][i] and !(cyc[x] and cyc[y]))) 
            x = up[x][i], y = up[y][i];
    int L = (x != y or !(cyc[x] and cyc[y])) ? up[x][0] : x;
    return (!L) ? -1 : vals[L];
}


# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7352 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7616 KB Output is correct
6 Correct 5 ms 7500 KB Output is correct
7 Correct 5 ms 7628 KB Output is correct
8 Correct 5 ms 7628 KB Output is correct
9 Correct 112 ms 29764 KB Output is correct
10 Correct 139 ms 34756 KB Output is correct
11 Correct 135 ms 34396 KB Output is correct
12 Correct 148 ms 36008 KB Output is correct
13 Correct 146 ms 39864 KB Output is correct
14 Correct 128 ms 30012 KB Output is correct
15 Correct 284 ms 39116 KB Output is correct
16 Correct 271 ms 38388 KB Output is correct
17 Correct 281 ms 39976 KB Output is correct
18 Correct 352 ms 43996 KB Output is correct
19 Correct 98 ms 16964 KB Output is correct
20 Correct 273 ms 40252 KB Output is correct
21 Correct 284 ms 39552 KB Output is correct
22 Correct 290 ms 41388 KB Output is correct
23 Correct 433 ms 45464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Incorrect 349 ms 45312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7352 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7616 KB Output is correct
6 Correct 5 ms 7500 KB Output is correct
7 Correct 5 ms 7628 KB Output is correct
8 Correct 5 ms 7628 KB Output is correct
9 Correct 4 ms 7352 KB Output is correct
10 Incorrect 5 ms 7616 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7352 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7616 KB Output is correct
7 Correct 5 ms 7500 KB Output is correct
8 Correct 5 ms 7628 KB Output is correct
9 Correct 5 ms 7628 KB Output is correct
10 Correct 112 ms 29764 KB Output is correct
11 Correct 139 ms 34756 KB Output is correct
12 Correct 135 ms 34396 KB Output is correct
13 Correct 148 ms 36008 KB Output is correct
14 Correct 146 ms 39864 KB Output is correct
15 Incorrect 5 ms 7616 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7352 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7616 KB Output is correct
6 Correct 5 ms 7500 KB Output is correct
7 Correct 5 ms 7628 KB Output is correct
8 Correct 5 ms 7628 KB Output is correct
9 Correct 112 ms 29764 KB Output is correct
10 Correct 139 ms 34756 KB Output is correct
11 Correct 135 ms 34396 KB Output is correct
12 Correct 148 ms 36008 KB Output is correct
13 Correct 146 ms 39864 KB Output is correct
14 Correct 128 ms 30012 KB Output is correct
15 Correct 284 ms 39116 KB Output is correct
16 Correct 271 ms 38388 KB Output is correct
17 Correct 281 ms 39976 KB Output is correct
18 Correct 352 ms 43996 KB Output is correct
19 Incorrect 349 ms 45312 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7352 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7616 KB Output is correct
7 Correct 5 ms 7500 KB Output is correct
8 Correct 5 ms 7628 KB Output is correct
9 Correct 5 ms 7628 KB Output is correct
10 Correct 112 ms 29764 KB Output is correct
11 Correct 139 ms 34756 KB Output is correct
12 Correct 135 ms 34396 KB Output is correct
13 Correct 148 ms 36008 KB Output is correct
14 Correct 146 ms 39864 KB Output is correct
15 Correct 128 ms 30012 KB Output is correct
16 Correct 284 ms 39116 KB Output is correct
17 Correct 271 ms 38388 KB Output is correct
18 Correct 281 ms 39976 KB Output is correct
19 Correct 352 ms 43996 KB Output is correct
20 Incorrect 349 ms 45312 KB Output isn't correct
21 Halted 0 ms 0 KB -