답안 #722567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722567 2023-04-12T10:47:49 Z Itamar Stranded Far From Home (BOI22_island) C++14
0 / 100
10 ms 19116 KB
// ConsoleApplication134.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#include <algorithm>
#include <queue>
#define pll pair<ll,ll>
const int siz = 2e5;
bool ans[siz];
ll cit[siz];
vi fr[siz];
int up[siz];
#include <set>
vector<pll> ord;

int my[siz];
vi col[siz];
ll sum[siz];
set<pll> out[siz];

int num[siz];
void uni(int i, int j) {
    if (my[i] == my[j])return;
    if (out[my[i]].size() < out[my[j]].size()) {
        swap(out[my[i]], out[my[j]]);
    }
    if (col[my[i]].size() < col[my[j]].size()) {
        swap(col[my[i]], col[my[j]]);
    }
    for (int v : col[my[j]]) {
        col[my[i]].push_back(v);
    }
    for (pll p : out[j]) {
        out[my[i]].insert(p);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> cit[i];
        ord.push_back({ cit[i],i });
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    ans[ord[n - 1].second] = 1;
    sort(ord.begin(), ord.end());
    for (int i = 0; i < n; i++) {
        num[ord[i].second] = i;
    }
    for (int i = 0; i < n; i++) {
        my[i] = i;
        col[i].push_back(i);
        sum[i] = cit[i];
        
        for (int f : fr[i]) {
            pi p1 = { cit[f],num[f] }, p2 = { cit[i], num[i] };
            if ( p1>p2 ) {
                out[i].insert({ cit[f],f });
            }
        }
    }
    for (int i = 0; i < n; i++)up[i] = -1;
    for (int i = 0; i < n; i++) {
        int j = ord[i].second;
        for (int f : fr[j]) {
            if (out[my[f]].find({ cit[j],j }) != out[my[f]].end())out[my[f]].erase({ cit[j],j });
        }
        for (int f : fr[ord[i].second]) {
            pi p1 = { cit[f],num[f] }, p2 = { cit[j], num[j] };
            if (p2 >= p1) {
                uni(j, f);
            }
        }
        if (i < n - 1) {
            pi p = *out[my[j]].begin();
            if (p.first <= sum[my[j]]) {
                up[j] = p.second;
            }
        }
    }
    for (int i = n - 2; i >= 0; i--) {
        if (up[i] != -1) {
            ans[i] = ans[up[i]];
        }
    }
    for (int i = 0; i < n; i++)if (ans[i])cout << '0'; else cout << '1';
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19108 KB Output is correct
3 Incorrect 9 ms 19028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Incorrect 9 ms 19116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19108 KB Output is correct
3 Incorrect 9 ms 19028 KB Output isn't correct
4 Halted 0 ms 0 KB -