Submission #748503

# Submission time Handle Problem Language Result Execution time Memory
748503 2023-05-26T11:36:21 Z inventiontime Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 20088 KB
#include <bits/stdc++.h>
using namespace std;

#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define pb push_back
#define re resize
#define ff first
#define ss second

#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)

#define print(x) cout << #x << ": " << x << endl << flush

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef vector<vi> vvi;
typedef priority_queue<int> pq;

template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }

const int inf = 1e17;

struct ufds {

    vi par;
    ufds(int n) : par(n, -1) {};
    ufds(vi a) : par(a) {
        for(int i = 0; i < par.size(); i++)
            par[i] = -par[i];
    };

    int find(int u) {
        if(par[u] < 0) return u;
        return par[u] = find(par[u]);
    }

    int size(int u) {
        return -par[find(u)];
    }

    bool merge(int u, int v) {
        u = find(u);
        v = find(v);
        if(u == v) return false;

        //if(size(u) < size(v)) swap(u, v);
        par[u] += par[v];
        par[v] = u;

        return true;
    }

};

void solve() {

    int n, m;
    cin >> n >> m;
    vi s(n+1);
    vii ss(n+1);
    vi adj[n+1];
    loop1(i, n)
        cin >> s[i];
    loop1(i, n)
        ss[i] = {s[i], i};
    sort(all1(ss));
    loop1(i, m) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    
    vb incl(n+1);
    ufds ufds(s);
    vb valid(n+1, true);
    loop1(i, n) {
        auto [su, u] = ss[i];
        incl[u] = true;
        for(auto v : adj[u]) if(incl[v]) {
            if(ufds.find(u) != ufds.find(v)) {
                if(ufds.size(v) < ufds.size(u)) {
                    loop1(i, n) {
                        if(ufds.find(i) == ufds.find(v))
                            valid[i] = false;
                    }
                }
            }
        }
        for(auto v : adj[u]) if(incl[v])
            ufds.merge(u, v);
    }

    loop1(i, n) cout << valid[i];
    cout << endl;

}

signed main() {

    fast_io;

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;

}

Compilation message

island.cpp: In constructor 'ufds::ufds(vi)':
island.cpp:40:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i = 0; i < par.size(); i++)
      |                        ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 9 ms 560 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 5 ms 420 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 7 ms 452 KB Output is correct
11 Correct 7 ms 548 KB Output is correct
12 Correct 4 ms 480 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 6 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1091 ms 20088 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1086 ms 19000 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1072 ms 20016 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 9 ms 560 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 5 ms 420 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 7 ms 452 KB Output is correct
11 Correct 7 ms 548 KB Output is correct
12 Correct 4 ms 480 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 6 ms 540 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 1091 ms 20088 KB Time limit exceeded
18 Halted 0 ms 0 KB -