이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vll vector<ll>
#define MAX 500005
#define pll pair<ll,ll>
#define F first
#define S second
vll v[MAX],r[MAX];
ll n,m,t,k,a[MAX],p[MAX],ans[MAX];
pll ord[MAX];
ll fnd(ll x){
// cout<<x<<p[x]<<"{\n";
if(p[x]==x){
// cout<<x<<"}\n";
return p[x];
}
p[x]=fnd(p[x]);
// cout<<x<<"}\n";
return p[x];
}
void uni(ll x,ll y){
x=fnd(x);y=fnd(y);
if(fnd(x)==fnd(y))return;
a[y]+=a[x];
p[x]=y;
}
int main(){
cin>>n>>m;map<ll,ll> mp;
for(int i=1;i<=n;i++){
cin>>a[i];p[i]=i;
ord[i]={a[i],i};
}
sort(ord+1,ord+n+1);
for(int i=1;i<=n;i++){
mp[ord[i].S]=i;
a[i]=ord[i].F;
}
ll a1,a2;
for(int i=0;i<m;i++){
cin>>a1>>a2;
a1=mp[a1];a2=mp[a2];
v[a1].push_back(a2);
v[a2].push_back(a1);
}
for(int i=1;i<=n;i++){
for(auto u : v[i]){
if(i<=u)continue;
ll x=fnd(u);
if(a[x]>=a[i] && ans[x]==0){
ans[x]=1;
r[i].push_back(x);
}
}
for(auto u : v[i]){
if(i<=u)continue;
ll x=fnd(u);
if(ans[x]==0)continue;
uni(x,i);ans[x]=0;
}
}
queue<ll> q;q.push(n);
while(!q.empty()){
ll u=q.front();q.pop();
ans[ord[u].S]=1;
for(auto w : r[u]){
if(ans[ord[w].S]==0)q.push(w);
}
}
for(int i=1;i<=n;i++){
cout<<ans[i];
}
return 0;
}
# | 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... |