답안 #308120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308120 2020-09-30T04:28:17 Z tjdgus4384 자매 도시 (APIO20_swap) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> group[100010];
vector<pair<int, int> > pa[100010];
vector<pair<int, pair<int, int> > > mv;
int p[100010], cycle[100010], outd[100010], sizep[100010], cnt[100010];

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

void init(int n, int m, vector<int> u, vector<int> v, vector<int> w){
    for(int i = 0;i < n;i++){
        sizep[i] = 1; p[i] = i;
        group[i].push_back(i);
        pa[i].push_back({0, i});
    }
    for(int i = 0;i < m;i++){
        mv.push_back({w[i], {u[i], v[i]}});
    }
    sort(mv.begin(), mv.end());
    /*for(int i = 0;i < m;i++){
        printf("%d %d %d\n", mv[i].first, mv[i].second.first, mv[i].second.second);
    }*/
    for(int i = 0;i < m;i++){
        int u1 = find(mv[i].second.first);
        int u2 = find(mv[i].second.second);
        cnt[mv[i].second.first]++; cnt[mv[i].second.second]++;
        if(u1 == u2){
            if(cycle[u1] == 0) cycle[u1] = mv[i].first;
            if(cnt[mv[i].second.first] >= 3 || cnt[mv[i].second.second] >= 3){
                if(outd[u1] == 0) outd[u1] = mv[i].first;
            }
        }
        else{
            if(sizep[u1] < sizep[u2]) swap(u1, u2);
            for(int j = 0;j < group[u2].size();j++){
                pa[group[u2][j]].push_back({mv[i].first, u1});
                p[group[u2][j]] = u1;
            }
            sizep[u1] += sizep[u2];
            if(cycle[u1] || cycle[u2]){
                if(cycle[u2] == 0) cycle[u2] = mv[i].first;
                if(cycle[u1] == 0) cycle[u1] = mv[i].first;
            }
            if(outd[u1] || outd[u2] || cnt[mv[i].second.first] >= 3 || cnt[mv[i].second.second] >= 3){
                if(outd[u1] == 0) outd[u1] = mv[i].first;
                if(outd[u2] == 0) outd[u2] = mv[i].first;
            }
        }
    }
}

int getMinimumFuelCapacity(int X, int Y){
    int x = X, y = Y, ans = 1000000001;
    int s1 = 0, e1 = pa[x].size() - 1;
    while(s1 < e1){
        int mid = (s1+e1)/2;
        if(cycle[pa[x][mid].second]||outd[pa[x][mid].second]) e1 = mid;
        else s1 = mid+1;
    }
    int s2 = 0, e2 = pa[y].size() - 1;
    while(s2 < e2){
        int mid = (s2+e2)/2;
        if(cycle[pa[y][mid].second]||outd[pa[y][mid].second]) e2 = mid;
        else s2 = mid+1;
    }
    if(cycle[pa[x][s1].second]) ans = min(ans, cycle[pa[x][s1].second]);
    if(outd[pa[y][s2].second]) ans = min(ans, outd[pa[y][s2].second]);
    if(outd[pa[x][s1].second]) ans = min(ans, outd[pa[x][s1].second]);
    if(cycle[pa[y][s2].second]) ans = min(ans, cycle[pa[y][s2].second]);
    if(ans == 1000000001) return -1;
    int s = 0, e = 1000000001;
    while(s < e){
        //printf("%d %d\n", s, e);
        int mid = (s+e)/2;
        s1 = 0, e1 = pa[x].size() - 1;
        while(s1 < e1){
            int mid1 = (s1+e1+1)/2;
            if(pa[x][mid1].first > mid) e1 = mid1-1;
            else s1 = mid1;
        }
        s2 = 0, e2 = pa[y].size() - 1;
        while(s2 < e2){
            int mid2 = (s2+e2+1)/2;
            if(pa[y][mid2].first > mid) e2 = mid2-1;
            else s2 = mid2;
        }
        if(pa[x][s1].second != pa[y][s2].second) s = mid+1;
        else e = mid;
    }
    else return max(ans, s);
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:38:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for(int j = 0;j < group[u2].size();j++){
      |                           ~~^~~~~~~~~~~~~~~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:93:5: error: 'else' without a previous 'if'
   93 |     else return max(ans, s);
      |     ^~~~