답안 #882720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882720 2023-12-03T14:05:34 Z 12345678 자매 도시 (APIO20_swap) C++17
6 / 100
236 ms 47208 KB
#include "swap.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=3e5+5, kx=19;
int lvl[nx], pa[nx][kx], dsu[nx], cnt, vl[nx], c[nx], f;
vector<tuple<int, int, int>> v;
vector<int> d[nx];

int find(int x)
{
    if (x==dsu[x]) return x;
    return dsu[x]=find(dsu[x]); 
}

void dfs(int u, int p)
{
    lvl[u]=lvl[p]+1; pa[u][0]=p;
    for (int i=1; i<kx; i++) pa[u][i]=pa[pa[u][i-1]][i-1];
    for (auto v:d[u])
    {
        if (v==p) continue;
        if (!c[v]) vl[v]=vl[u];
        dfs(v, u);
    }
}

int lca(int u, int v)
{
    if (lvl[u]>lvl[v]) swap(u, v);
    for (int i=kx-1; i>=0; i--) if (lvl[pa[v][i]]>=lvl[u]) v=pa[v][i];
    if (u==v) return u;
    for (int i=kx-1; i>=0; i--) if (pa[u][i]!=pa[v][i]) u=pa[u][i], v=pa[v][i];
    return pa[u][0];
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    cnt=N;
    for (int i=0; i<nx; i++) dsu[i]=i;
    for (int i=0; i<M; i++) v.push_back({W[i], U[i], V[i]});
    sort(v.begin(), v.end());
    for (auto [z, x, y]:v)
    {
        vl[cnt]=z;
        if (find(x)==find(y)) d[cnt].push_back(find(x)), dsu[find(x)]=cnt, c[cnt++]=1;
        else
        {
            int px=find(x), py=find(y);
            dsu[px]=cnt; dsu[py]=cnt;
            d[cnt].push_back(px);
            d[cnt].push_back(py);
            //cout<<px<<' '<<py<<' '<<d[px].size()<<' '<<d[py].size()<<'\n';
            c[cnt++]=c[px]||c[py]||d[x].size()==2||d[y].size()==2;
        }
    }
    if (!c[cnt-1]) f=1;
    else dfs(cnt-1, cnt-1);
}

int getMinimumFuelCapacity(int X, int Y) {
    if (f) return -1;
    else return vl[lca(X, Y)];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12920 KB Output is correct
5 Correct 3 ms 12904 KB Output is correct
6 Correct 3 ms 12932 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 35 ms 19704 KB Output is correct
10 Correct 42 ms 21192 KB Output is correct
11 Correct 42 ms 21192 KB Output is correct
12 Correct 47 ms 21632 KB Output is correct
13 Correct 41 ms 22136 KB Output is correct
14 Correct 38 ms 20088 KB Output is correct
15 Correct 96 ms 25336 KB Output is correct
16 Correct 85 ms 25208 KB Output is correct
17 Correct 85 ms 25604 KB Output is correct
18 Correct 82 ms 26264 KB Output is correct
19 Correct 78 ms 21516 KB Output is correct
20 Correct 177 ms 43532 KB Output is correct
21 Correct 173 ms 41588 KB Output is correct
22 Correct 221 ms 44056 KB Output is correct
23 Correct 236 ms 47208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Incorrect 85 ms 24664 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12920 KB Output is correct
5 Correct 3 ms 12904 KB Output is correct
6 Correct 3 ms 12932 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Incorrect 3 ms 12888 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12920 KB Output is correct
6 Correct 3 ms 12904 KB Output is correct
7 Correct 3 ms 12932 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12892 KB Output is correct
10 Correct 35 ms 19704 KB Output is correct
11 Correct 42 ms 21192 KB Output is correct
12 Correct 42 ms 21192 KB Output is correct
13 Correct 47 ms 21632 KB Output is correct
14 Correct 41 ms 22136 KB Output is correct
15 Incorrect 3 ms 12888 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12920 KB Output is correct
5 Correct 3 ms 12904 KB Output is correct
6 Correct 3 ms 12932 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 35 ms 19704 KB Output is correct
10 Correct 42 ms 21192 KB Output is correct
11 Correct 42 ms 21192 KB Output is correct
12 Correct 47 ms 21632 KB Output is correct
13 Correct 41 ms 22136 KB Output is correct
14 Correct 38 ms 20088 KB Output is correct
15 Correct 96 ms 25336 KB Output is correct
16 Correct 85 ms 25208 KB Output is correct
17 Correct 85 ms 25604 KB Output is correct
18 Correct 82 ms 26264 KB Output is correct
19 Incorrect 85 ms 24664 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12920 KB Output is correct
6 Correct 3 ms 12904 KB Output is correct
7 Correct 3 ms 12932 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12892 KB Output is correct
10 Correct 35 ms 19704 KB Output is correct
11 Correct 42 ms 21192 KB Output is correct
12 Correct 42 ms 21192 KB Output is correct
13 Correct 47 ms 21632 KB Output is correct
14 Correct 41 ms 22136 KB Output is correct
15 Correct 38 ms 20088 KB Output is correct
16 Correct 96 ms 25336 KB Output is correct
17 Correct 85 ms 25208 KB Output is correct
18 Correct 85 ms 25604 KB Output is correct
19 Correct 82 ms 26264 KB Output is correct
20 Incorrect 85 ms 24664 KB Output isn't correct
21 Halted 0 ms 0 KB -