Submission #860988

#TimeUsernameProblemLanguageResultExecution timeMemory
860988CookieStranded Far From Home (BOI22_island)C++14
100 / 100
90 ms18096 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define vt vector #define pb push_back #define pii pair<int, int> #define sz(dq) (int)dq.size() #define forr(i, a, b) for(int i = a; i < b; i++) #define fi first #define se second #define pll pair<ll, ll> ifstream fin("store.inp"); ofstream fout("store.out"); const ll mxn = 3e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353; //const int x[4] = {0, -1, 0, 1}; int n, m; struct E{ ll u, v, w; bool operator <(const E &b){ return(w < b.w); } }; vt<E>edge; bool bad[mxn + 1]; int pa[mxn + 1]; ll sm[mxn + 1], c[mxn + 1]; int fp(int u){ if(pa[u] == u)return(u); int v = fp(pa[u]); bad[u] |= bad[pa[u]]; pa[u] = v; return(v); } void unon(int u, int v){ u = fp(u); v = fp(v); if(u == v)return; if(c[u] < c[v])swap(u, v); if(c[u] > sm[v])bad[v] = 1; pa[v] = u; sm[u] += sm[v]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> c[i]; pa[i] = i; sm[i] = c[i]; } for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; edge.pb({u, v, max(c[u], c[v])}); } sort(edge.begin(), edge.end()); for(auto [u, v, w]: edge){ unon(u, v); } for(int i = 1; i <= n; i++){ //cout << bad[i] << " " << pa[i] << "\n"; } for(int i = 1; i <= n; i++){ fp(i); cout << !bad[i]; } return(0); }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [u, v, w]: edge){
      |              ^
#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...