답안 #1103414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103414 2024-10-20T23:53:09 Z aaaaaarroz 나일강 (IOI24_nile) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Dsu {
    ll cnt;
    vector<ll> parent, rank, size;

    Dsu(ll N) {
        cnt = 2 * N;
        parent.resize(N);
        rank.resize(N);
        size.resize(N, 1);
        for (ll i = 0; i < N; i++) {
            parent[i] = i;
        }
    }

    bool isSameSet(ll i, ll j) {
        return findSet(i) == findSet(j);
    }

    ll findSet(ll i) { 
        if (parent[i] == i) {
            return i;
        } else {
            return parent[i] = findSet(parent[i]);
        } 
    }

    void unionSet(ll i, ll j) {
        ll x = findSet(i);
        ll y = findSet(j);
        if (x != y) {
            cnt -= 2;  // Restar siempre que una unión ocurra

            if (rank[x] > rank[y]) {
                parent[y] = x;
                size[x] += size[y];
            } else if (rank[x] < rank[y]) {
                parent[x] = y;
                size[y] += size[x];
            } else {
                parent[x] = y;
                size[y] += size[x];
                rank[y]++;
            }
        }
    }

    ll res() {
        return cnt;
    }
};

vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {                   
    vector<pair<ll, int>> sorted_W;
    ll n = W.size();

    for (int i = 0; i < n; i++) {
        sorted_W.push_back({W[i], i});
    }
    sort(sorted_W.begin(), sorted_W.end());

    vector<int> new_A(n), new_B(n);
    for (int i = 0; i < n; i++) {
        new_A[i] = A[sorted_W[i].second];
        new_B[i] = B[sorted_W[i].second];
    }
    A = new_A;
    B = new_B;

    Dsu dsu(n);
    vector<vector<ll>> edges;
    
    for (ll i = 0; i < n - 1; i++) {
        edges.push_back({abs(sorted_W

Compilation message

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:77:38: error: expected ')' at end of input
   77 |         edges.push_back({abs(sorted_W
      |                             ~~~~~~~~~^
      |                                      )
nile.cpp:77:30: error: expected '}' at end of input
   77 |         edges.push_back({abs(sorted_W
      |                         ~    ^~~~~~~~
nile.cpp:77:38: error: expected ')' at end of input
   77 |         edges.push_back({abs(sorted_W
      |                        ~     ~~~~~~~~^
      |                                      )
nile.cpp:77:30: error: expected '}' at end of input
   77 |         edges.push_back({abs(sorted_W
      |                              ^~~~~~~~
nile.cpp:76:36: note: to match this '{'
   76 |     for (ll i = 0; i < n - 1; i++) {
      |                                    ^
nile.cpp:77:30: error: expected '}' at end of input
   77 |         edges.push_back({abs(sorted_W
      |                              ^~~~~~~~
nile.cpp:56:88: note: to match this '{'
   56 | vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
      |                                                                                        ^
nile.cpp:77:30: warning: no return statement in function returning non-void [-Wreturn-type]
   77 |         edges.push_back({abs(sorted_W
      |                              ^~~~~~~~