답안 #573288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573288 2022-06-06T11:15:39 Z AmirElarbi Stranded Far From Home (BOI22_island) C++14
0 / 100
114 ms 121136 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9+7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 4e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
vii s;
vi adj[nax], nds[nax];
ll ans[nax];
ll p[nax], sz[nax];
bool vis[nax];
int find_set(int v) {
    if (v == p[v])
        return v;
    return p[v] = find_set(p[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b){
        if(nds[b].size() > nds[a].size()) swap(nds[a],nds[b]);
        for(auto x : nds[b]) nds[a].pb(x);
        p[b] = a;
        sz[a] += sz[b];
    }
}
int main(){
    optimise;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n,m;
    cin >>n >> m;
    for (int i = 0; i < n; ++i)
    {
        int val;
        cin >> val;
        sz[i] = val;
        p[i] = i;
        nds[i].pb(i);
        s.pb({val,i});
    }
    for (int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; ++i)
    {
        int u = find_set(s[i].se);
        for(auto x : adj[u]){
            if(!vis[x]) continue;
            x = find_set(x);
            if(sz[u] > sz[x]) nds[x].clear();
        }
        for(auto x : adj[u]) if(vis[x]) union_sets(x,u);
        vis[u] = 1;  
    }
    for(auto x: nds[find_set(0)]) ans[x] = 1;
    for (int i = 0; i < n; ++i)
    {
        cout << ans[i];
    }
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 38612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 38652 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 114 ms 121136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 38716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 38612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -