Submission #579826

#TimeUsernameProblemLanguageResultExecution timeMemory
579826balbitStranded Far From Home (BOI22_island)C++14
100 / 100
278 ms44208 KiB
#include <bits/stdc++.h> using namespace std; #define int ll #define ll long long #define pii pair<ll, ll> #define f first #define s second #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define pb push_back #define MX(a,b) a=max(a,b) #define MN(a,b) a = min(a,b) #define FOR(i,a,b) for (int i = a; i<b; ++i) #define REP(i,n) FOR(i,0,n) #define REP1(i,n) FOR(i,1,n+1) #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do( T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);} #else #define bug(...) #define endl '\n' #endif // BALBIT const int maxn = 2e5+5; vector<int> alive[maxn]; int S[maxn]; int iv[maxn]; int par[maxn]; vector<int> g[maxn]; int find(int x) { return x == par[x]? x : par[x] = find(par[x]);} void test(int p, int rnd) { p = find(p); if (S[p] < rnd) { alive[p].clear(); } } void mrg(int a, int b, int t) { bug("mrg", a,b,t); a = find(a); b =find(b); if (a == b) return; test(a,t); test(b,t); if (SZ(alive[a]) < SZ(alive[b])) swap(a,b); // a is bigger alive[a].insert(alive[a].end(), ALL(alive[b])); par[b] = a; S[a] += S[b]; } signed main(){ ios::sync_with_stdio(0), cin.tie(0); bug(1,2); int n,m; cin>>n>>m; vector<pii> go; REP(i,n) { cin>>S[i]; iv[i] = S[i]; go.pb({S[i], i}); alive[i].pb(i); par[i] = i; } REP(i,m) { int a,b; cin>>a>>b; --a; --b; g[a].pb(b); g[b].pb(a); } sort(ALL(go)); for (pii p : go) { int who = p.s, val = p.f; for (int u : g[who]) { if (iv[u] <= val) mrg(who, u, val); } } vector<int> ret(n); for (int e : alive[find(0)]) ret[e] = 1; REP(i,n) cout<<ret[i]; cout<<endl; }
#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...