답안 #941326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941326 2024-03-08T13:45:11 Z prairie2022 Stranded Far From Home (BOI22_island) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define F first 
#define S second

vector<int> dsu[2]; // biggest in group, discard?, sum of popularity

inline int boss(int u, bool b){
    int &bs = dsu[b][u];
    if(bs==u) return u;
    return bs = boss(bs, b);
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    fill(dsu, dsu+3, vector<int>(n+1));
    dsu[1][0] = 0;

    vector<pair<ll, int>> s(n+1);
    for(int i=1; i<=n; i++){
        cin >> s[i].F;
        s[i].S = i;
    }
    vector<vector<int>> e(n+1);
    while(m--){
        int a, b;
        cin >> a >> b;
        if(s[a]<s[b]) swap(a, b);
        e[a].push_back(b);
    }

    s[0] = {INT32_MAX, 0};
    sort(s.begin(), s.end());
    s.pop_back();

    vector<ll> tot(n+1);
    for(const auto &[num, i] : s){
        dsu[0][i] = dsu[1][i] = i;
        tot[i] = num;
        for(int v: e[i]){
            v = boss(v, 0);
            if(v==i) continue;
            dsu[0][v] = i;
            dsu[1][v] = (tot[v]>=num)?i:0;
            tot[i] += tot[v];
        }
    }
    for(int i=1; i<=n; i++) cout << "10"[!boss(i, 1)];
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:20:9: warning: array subscript 3 is outside array bounds of 'std::vector<int> [2]' [-Warray-bounds]
   20 |     fill(dsu, dsu+3, vector<int>(n+1));
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:8:13: note: while referencing 'dsu'
    8 | vector<int> dsu[2]; // biggest in group, discard?, sum of popularity
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -