답안 #598037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598037 2022-07-17T12:12:26 Z boris_mihov Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 31192 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9 + 10;

int n, m;
int a[MAXN], s[MAXN], inS[MAXN];
std::vector < int > g[MAXN];
std::vector < int > alive[MAXN];
struct DSUelement
{
    int par;
    int sum;
} c[MAXN];

int find(int x)
{
    if (c[x].par == x) return x;
    return c[x].par = find(c[x].par);
}

void connect(int x, int y)
{
    x = find(x);
    y = find(y);
    if (alive[x].size() > alive[y].size()) std::swap(x, y);
    c[x].par = y;
    c[y].sum += c[x].sum;
    c[y].sum = std::min(c[y].sum, INF);
    alive[y].reserve(alive[x].size() + alive[y].size());
    for (int i : alive[x])
    {
        alive[y].push_back(i);
    }
}

bool areConnected(int x, int y)
{
    return find(x) == find(y);
}

char ans[MAXN];
void solve()
{
    std::iota(s+1, s+n+1, 1);
    std::sort(s+1, s+n+1, [&](int x, int y)
    {
        return a[x] < a[y];
    });

    for (int i = 1 ; i <= n ; ++i)
    {
        inS[s[i]] = i;
        c[i].par = i;
        c[i].sum = a[i];
        alive[i].push_back(i);
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        int x = s[i];
        for (const int &j : g[x])
        {
            if (inS[j] > i || areConnected(x, j)) continue;
            int par = find(j);
            if (c[par].sum < a[x])
            {
                alive[par].clear();
            }

            connect(x, j);
        }
    }

    int findPar = find(1);
    std::fill(ans, ans+n, '0');
    for (int i : alive[findPar])
    {
        ans[i-1] = '1';
    }

    ans[n] = '\0';
    std::cout << ans << '\n';
}

void read()
{
    std::cin >> n >> m;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }

    for (int i = 1 ; i <= m ; ++i)
    {
        int x, y;
        std::cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 6 ms 9812 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 6 ms 9824 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 8 ms 9812 KB Output is correct
9 Correct 7 ms 9928 KB Output is correct
10 Correct 7 ms 9888 KB Output is correct
11 Correct 6 ms 9960 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9624 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Execution timed out 1094 ms 27312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 194 ms 29572 KB Output is correct
3 Correct 239 ms 29600 KB Output is correct
4 Correct 168 ms 30896 KB Output is correct
5 Correct 168 ms 30996 KB Output is correct
6 Correct 199 ms 29576 KB Output is correct
7 Execution timed out 1086 ms 27028 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 902 ms 28240 KB Output is correct
3 Correct 426 ms 28760 KB Output is correct
4 Correct 232 ms 30120 KB Output is correct
5 Correct 568 ms 31192 KB Output is correct
6 Execution timed out 1085 ms 28088 KB Time limit exceeded
7 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 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 7 ms 9940 KB Output is correct
6 Correct 6 ms 9824 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 8 ms 9812 KB Output is correct
9 Correct 7 ms 9928 KB Output is correct
10 Correct 7 ms 9888 KB Output is correct
11 Correct 6 ms 9960 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 5 ms 9624 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Execution timed out 1094 ms 27312 KB Time limit exceeded
18 Halted 0 ms 0 KB -