Submission #748505

#TimeUsernameProblemLanguageResultExecution timeMemory
748505inventiontimeStranded Far From Home (BOI22_island)C++17
100 / 100
464 ms80932 KiB
#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; vector<set<int>> st; ufds(vi a) : par(a), st(par.size()) { for(int i = 0; i < par.size(); i++) { par[i] = -par[i]; st[i].insert(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(st[u].size() < st[v].size()) swap(u, v); for(auto x : st[v]) st[u].insert(x); par[u] += par[v]; par[v] = u; return true; } set<int>& setof(int u) { return st[find(u)]; } }; 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)) { set<int>& st = ufds.setof(v); for(auto x : st) valid[x] = false; st.clear(); } } } 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 (stderr)

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 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...