| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1287046 | nlhuy | Stranded Far From Home (BOI22_island) | C++20 | 202 ms | 37120 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define Task "test"
typedef pair<int,int>ii;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const int Maxn = 2e5+7;
const int di[] = {0, 0, -1, 1};
const int dj[] = {-1, 1, 0, 0};
vector<int>node[Maxn],g[Maxn];
ll sum[Maxn];
int par[Maxn],res[Maxn];
bool vis[Maxn];
ii a[Maxn];
void make_set(int n){
for(int i=1;i<=n;i++) par[i]=i,node[i].push_back(i),sum[i]=a[i].fi;
}
int find_set(int x){
if (x==par[x]) return x;
return par[x]=find_set(par[x]);
}
void unite(int a,int b){
a=find_set(a);
b=find_set(b);
if (a==b) return;
if (node[a].size()<node[b].size()) swap(a,b);
sum[a]+=sum[b];
for(int x:node[b]) node[a].push_back(x);
node[b].clear();
par[b]=a;
}
void run_case(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i].fi,a[i].se=i;
while(m--){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
make_set(n);
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) res[i]=1,vis[i]=0;
for(int i=1;i<=n;i++){
vis[a[i].se]=1;
for(int v:g[a[i].se]){
if (vis[v]){
int u=find_set(v);
if (sum[u]<a[i].fi){
for(int x:node[u]) res[x]=0;
}
}
}
for(int v:g[a[i].se]){
if (vis[v]) unite(a[i].se,v);
}
}
for(int i=1;i<=n;i++) cout<<res[i];
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(Task ".inp", "r"))
{
freopen(Task ".inp", "r", stdin);
freopen(Task ".out", "w", stdout);
}
int t = 1;
//cin >> t;
while(t--){
run_case();
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
