답안 #602207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602207 2022-07-22T17:15:08 Z Vanilla Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 31556 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 <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(y);
        ad[y].push_back(x);
    }
    sort(v.begin(), v.end());
    for (auto [val, x]: v) {
        for (auto y: ad[x]) {
            if (a[y] > a[x]) continue;
            int p1 = dad(x), p2 = dad(y);
            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 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 8 ms 9812 KB Output is correct
5 Correct 13 ms 9936 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 9 ms 9876 KB Output is correct
8 Correct 9 ms 9812 KB Output is correct
9 Correct 7 ms 9972 KB Output is correct
10 Correct 10 ms 9940 KB Output is correct
11 Correct 9 ms 9940 KB Output is correct
12 Correct 8 ms 9812 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Execution timed out 1089 ms 29352 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 1087 ms 31556 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9696 KB Output is correct
2 Execution timed out 1092 ms 29452 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 8 ms 9812 KB Output is correct
5 Correct 13 ms 9936 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 9 ms 9876 KB Output is correct
8 Correct 9 ms 9812 KB Output is correct
9 Correct 7 ms 9972 KB Output is correct
10 Correct 10 ms 9940 KB Output is correct
11 Correct 9 ms 9940 KB Output is correct
12 Correct 8 ms 9812 KB Output is correct
13 Correct 7 ms 9812 KB Output is correct
14 Correct 7 ms 9848 KB Output is correct
15 Correct 5 ms 9720 KB Output is correct
16 Correct 7 ms 9684 KB Output is correct
17 Execution timed out 1089 ms 29352 KB Time limit exceeded
18 Halted 0 ms 0 KB -