답안 #602203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602203 2022-07-22T17:09:30 Z Vanilla Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 31596 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
int a[maxn], dsu[maxn];
int64 sum[maxn];
vector <pair <int, int> > ad [maxn];
vector <int> comp [maxn];
int rs [maxn];

int dad (int x) {
    return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}

int main() {
    int n,m;
    cin >> n >> m;
    vector <pair <int, int> > v;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        dsu[i] = i;
        sum[i] = a[i];
        comp[i].push_back(i);
        v.push_back({a[i], i});
    }
    for (int i = 1; i <= m; i++){
        int x,y;
        cin >> x >> y;
        ad[x].push_back({a[y], y});
        ad[y].push_back({a[x], x});
    }
    sort(v.begin(), v.end());
    for (auto [val, x]: v) {
        sort(ad[x].rbegin(), ad[x].rend());
        while (!ad[x].empty() && ad[x].back().first <= val) {
            int y = ad[x].back().second;
            int p1 = dad(x), p2 = dad(y);
            // cout << x << " " << y << p1 << " " << p2 << "\n";
            if (val > sum[p2]) comp[p2].clear();
            if (p1 != p2) {
                if (comp[p1].size() < comp[p2].size()) swap(p1, p2);
                dsu[p2] = p1;
                sum[p1] += sum[p2];
                while (!comp[p2].empty()) {
                    comp[p1].push_back(comp[p2].back());
                    comp[p2].pop_back();
                }
            }
            ad[x].pop_back();
        }
    }
    map <int, int> dd;
    for (int i = 1; i <= n; i++){
        if (!dd.count(dad(i))) {
            dd[i] = 1;
            for (int j: comp[dad(i)]) rs[j] = 1;
        }
    }
    for (int i = 1; i <= n; i++) cout << rs[i] << "";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 9 ms 9860 KB Output is correct
5 Correct 12 ms 10012 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 10 ms 9928 KB Output is correct
8 Correct 10 ms 9884 KB Output is correct
9 Correct 7 ms 10000 KB Output is correct
10 Correct 11 ms 9964 KB Output is correct
11 Correct 11 ms 9940 KB Output is correct
12 Correct 9 ms 9880 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 8 ms 9928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Execution timed out 1092 ms 30184 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Execution timed out 1098 ms 31596 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1099 ms 30520 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 9 ms 9860 KB Output is correct
5 Correct 12 ms 10012 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 10 ms 9928 KB Output is correct
8 Correct 10 ms 9884 KB Output is correct
9 Correct 7 ms 10000 KB Output is correct
10 Correct 11 ms 9964 KB Output is correct
11 Correct 11 ms 9940 KB Output is correct
12 Correct 9 ms 9880 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 8 ms 9928 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Execution timed out 1092 ms 30184 KB Time limit exceeded
18 Halted 0 ms 0 KB -