# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
581862 | 2022-06-23T07:30:05 Z | temporary_juggernaut | Stranded Far From Home (BOI22_island) | C++14 | 5 ms | 4952 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif ll a[200005]; int par[200005]; ll sum[200005]; vector<int>comp[200005]; ll mx[200005]; pair<int,int>edge[200005]; int n,m; int cash; bool cmp(pair<int,int>l,pair<int,int>r){ if(a[l.fr]==a[r.fr])return a[l.sc]<a[r.sc]; return a[l.fr]<a[r.fr]; } int fin(int v){return v==par[v]?v:par[v]=fin(par[v]);} void unite(int a,int b){ a=fin(a); b=fin(b); if(a==b)return; if(comp[a].size()<comp[b].size())swap(a,b); if(sum[a]<mx[b])comp[a].clear(); if(sum[b]<mx[a])comp[b].clear(); par[b]=a; umax(mx[a],mx[b]); sum[a]+=sum[b]; cash=a; for(int to:comp[b])comp[a].push_back(to); comp[b].clear(); } int ans[200005]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); mx[i]=a[i]; sum[i]=a[i]; comp[i].push_back(i); par[i]=i; } for(int i=1;i<=m;i++){ scanf("%d%d",&edge[i].fr,&edge[i].sc); if(a[edge[i].fr]<a[edge[i].sc])swap(edge[i].fr,edge[i].sc); } sort(edge+1,edge+1+m,cmp); for(int i=1;i<=m;i++)unite(edge[i].fr,edge[i].sc); for(int to:comp[cash])ans[to]=1; for(int i=1;i<=n;i++)printf("%d",ans[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Incorrect | 3 ms | 4948 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Incorrect | 3 ms | 4948 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 4952 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Incorrect | 3 ms | 4948 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |