답안 #395202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395202 2021-04-28T02:06:45 Z Erkhemkhuu 자매 도시 (APIO20_swap) C++17
0 / 100
104 ms 15768 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int lg = 18;
int tin[N], tout[N];
int depth[N], timer, anc[N][lg];
int n, m;
int par[N], sz[N], cnt[N];
bool done[N];
vector <tuple <int, int, int> > edges;
/*
bool is_ancestor(int v, int u) {
    return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
int go_up(int v, int u) {
    for(int i = lg - 1; i >= 0; i--)
        if(!is_ancestor(anc[v][i], u))
            v = anc[v][i];
    return v;
}
void dfs(int v, int p) {
    tin[v] = ++timer;
    anc[v][0] = p;
    for(int i = 1; i < lg; i++)
        anc[v][i] = anc[anc[v][i - 1]][i - 1];
    for(auto &u: v) {
        if(u == p) continue;
        depth[u] = depth[v] + 1;
        dfs(u, v);
    }
    tout[v] = ++timer;
    return;
}
int lca(int v, int u) {
    if(is_ancestor(v, u)) return v;
    if(is_ancestor(u, v)) return u;
    return anc[go_up(v, u)][0];
}
*/
int get(int x) {
    return ((x == par[x]) ? (x) : (par[x] = get(par[x])));
}
void init(int N, int M, vector <int> V, vector <int> U, vector <int> W) {
    n = N; m = M;
    for(int i = 0; i < m; i++)
        edges.push_back({W[i], V[i], U[i]});
    return;
}
void prepare() {
    for(int i = 1; i <= n; i++) {
        par[i] = i;
        sz[i] = 1;
        cnt[i] = 0;
        done[i] = false;
    }
    return;
}
int getMinimumFuelCapacity(int v, int u) {
    prepare();
    sort(edges.begin(), edges.end());
    for(auto &it: edges) {
        int x, y, z;
        tie(x, y, z) = it;
        cnt[x]++; cnt[y]++;

        int X = get(x);
        int Y = get(Y);

        bool flag = (X == Y);
        flag |= (cnt[x] >= 3 || cnt[y] >= 3);
        if(flag) done[X] = true;

        if(sz[X] < sz[Y]) swap(X, Y);
        sz[X] += sz[Y];
        done[X] |= done[Y];
        par[Y] = X;

        if(get(v) == get(u) && done[get(v)])
            return z;
    }
    return -1;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:41:24: warning: 'Y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     return ((x == par[x]) ? (x) : (par[x] = get(par[x])));
      |                   ~~~~~^
swap.cpp:67:13: note: 'Y' was declared here
   67 |         int Y = get(Y);
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Runtime error 2 ms 460 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Runtime error 104 ms 15768 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Runtime error 2 ms 460 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Runtime error 2 ms 460 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Runtime error 2 ms 460 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Runtime error 2 ms 460 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -