답안 #941325

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

#define F first 
#define S second

const int M = 2e5+1;
vector<int> dsu[3]; // 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();

    for(const auto &[num, i] : s){
        dsu[0][i] = dsu[1][i] = i;
        dsu[2][i] = num;
        for(int v: e[i]){
            v = boss(v, 0);
            if(v==i) continue;
            dsu[0][v] = i;
            dsu[1][v] = (dsu[2][v]>=num)?i:0;
            dsu[2][i] += dsu[2][v];
        }
    }
    for(int i=1; i<=n; i++) cout << "10"[!boss(i, 1)];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 524 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Incorrect 73 ms 19464 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 88 ms 19140 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 122 ms 18968 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 524 KB Output isn't correct
5 Halted 0 ms 0 KB -