Submission #1155481

#TimeUsernameProblemLanguageResultExecution timeMemory
1155481CrabCNHStranded Far From Home (BOI22_island)C++20
0 / 100
78 ms11188 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 2e5 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

int n, m;
int a[maxN], par[maxN], mxSz[maxN];
bool aval[maxN];
vector <tuple <int, int, int>> all;

void init () {
    for (int i = 1; i <= n; i ++) {
        par[i] = i;
        mxSz[i] = a[i];
    }
}

int getRoot (int u) {
    if (par[u] == u) {
        return u;
    }
    aval[u] |= aval[par[u]];
    return (par[u] = getRoot (par[u]));
}

void merge (int u, int v) {
    u = getRoot (u);
    v = getRoot (v);
    if (u == v) {  // Sửa điều kiện hợp nhất
        return;
    }
    if (mxSz[v] < a[u]) {
        aval[v] = true;
    }
    par[v] = u;
    mxSz[u] += mxSz[v];
}

void solve () {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    init ();
    for (int i = 1; i <= m; i ++) {
        int u, v;
        cin >> u >> v;
        if (a[u] < a[v]) {
            swap (u, v);
        }
        all.push_back ({a[u], u, v});
    }
    sort (all.begin (), all.end ());
    for (auto [_, u, v] : all) {
        merge (u, v);     
    }
    for (int i = 1; i <= n; i ++) {
        int t = getRoot (i);
        cout << !aval[t];
    }
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:81:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:82:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...