답안 #1104157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104157 2024-10-23T03:41:16 Z Ice_man Stranded Far From Home (BOI22_island) C++14
0 / 100
250 ms 57160 KB
/**
 ____    ____    ____    __________________    ____    ____    ____
||I ||  ||c ||  ||e ||  ||                ||  ||M ||  ||a ||  ||n ||
||__||  ||__||  ||__||  ||________________||  ||__||  ||__||  ||__||
|/__\|  |/__\|  |/__\|  |/________________\|  |/__\|  |/__\|  |/__\|

*/

#include <iostream>
#include <chrono>
#include <set>
#include <algorithm>
#include <vector>

#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;


typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double pd;


std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}


int n, m;
int s[maxn];
set <int> v[maxn];
pii sorted[maxn];

void read()
{
    cin >> n >> m;

    for(int i = 1; i <= n; i++)
        cin >> s[i];

    for(int i = 1; i <= n; i++)
        sorted[i] = {s[i], i};

    int x, y;
    for(int i = 1; i <= m; i++)
    {
        cin >> x >> y;

        v[x].insert(y);
        v[y].insert(x);
    }
    sort(sorted + 1, sorted + 1 + n);

    /**for(int i = 1; i <= n; i++)
        cout << sorted[i].X << " " << sorted[i].Y << endl;*/
}

int par[maxn], sz[maxn], sum[maxn];
bool lamp[maxn];
set <int> nodes[maxn];

int f(int node)
{
    return node == par[node]? node : par[node] = f(par[node]);
}


void unite(int a, int b)
{
    a = f(a);
    b = f(b);

    if(a == b)
        return;

    if(sz[b] > sz[a])
        swap(a, b);

    for(auto e : nodes[b])
        nodes[a].insert(e);
    sum[a] += sum[b];
    par[b] = a;
    sz[a] += sz[b];
}



void solve()
{
    for(int i = 1; i <= n; i++)
    {
        nodes[i].clear();
        par[i] = i;
        sz[i] = 1;
        lamp[i] = false;
        sum[i] = 0;
    }

    for(int i = 1; i <= n; i++)
    {
        int curr = sorted[i].Y;
        
        //cout << curr << endl;
        
        vector <int> act;

        for(auto e : v[curr])
            if(lamp[e] == true)
                act.pb(f(e));

        lamp[curr] = true;
        nodes[curr].insert(curr);
        sum[curr] = s[curr];

        for(auto e : act)
            if(s[curr] > sum[e])
            {
                nodes[e].clear();
                unite(e, curr);
            }
        for(auto e : act)
            unite(e , curr);
    }

    for(int i = 1; i <= n; i++)
    {
        int a = f(1);

        auto p1 = nodes[a].find(i);
        if(p1 == nodes[a].end())
            cout << '0';
        else
            cout << '1';
    }
}




int main()
{

    /**#ifdef ONLINE_JUDGE /// promeni
        freopen("taxi.in", "r", stdin);
        freopen("taxi.out", "w", stdout);
    #endif*/

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    startT = std::chrono::high_resolution_clock::now();


    read();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23368 KB Output is correct
3 Correct 4 ms 23228 KB Output is correct
4 Incorrect 5 ms 23632 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23372 KB Output is correct
3 Incorrect 181 ms 57160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Incorrect 250 ms 56276 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23136 KB Output is correct
2 Incorrect 222 ms 55952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23368 KB Output is correct
3 Correct 4 ms 23228 KB Output is correct
4 Incorrect 5 ms 23632 KB Output isn't correct
5 Halted 0 ms 0 KB -