#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll sum[2000005];
ll par[2000005];
ll find_par(ll x){
if(par[x] == x){
return x;
}
return par[x] = find_par(par[x]);
}
void enose(ll a,ll b){
ll p1 = find_par(a);
ll p2 = find_par(b);
if(p1 != p2){
par[p1] = p2;
sum[p2] += sum[p1];
sum[p1] = 0;
}
}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,m;
cin>>n>>m;
f(i,1,n+1){
par[i] = i;
}
ll s[n];
vector<ii>exo;
ll maxxi = 0;
f(i,0,n){
cin>>s[i];
sum[i+1] = s[i];
maxxi = max(maxxi,s[i]);
exo.pb(ii(s[i],i+1));
}
vector<iii>edges;
f(i,0,m){
ll a,b;
cin>>a>>b;
if(s[a-1] > s[b-1]){
swap(a,b);
}
edges.pb(iii(s[b-1],ii(a,b)));
}
sort(all(edges));
sort(all(exo));
ll pos = 0;
ll posa[n];
ll maxi[n+5] = {0};
ll p[n];
ll Next[n+5];
bool ok[n];
for(auto x:exo){
while(pos < m && edges[pos].F <= x.F){
maxi[find_par(edges[pos].S.F)] = edges[pos].F;
Next[find_par(edges[pos].S.F)] = edges[pos].S.F - 1;
enose(edges[pos].S.F,edges[pos].S.S);
pos++;
}
posa[x.S - 1] = sum[find_par(x.S)];
p[x.S - 1] = find_par(x.S);
}
reverse(all(exo));
for(auto x:exo){
if(x.F != maxxi){
ok[x.S - 1] = ok[Next[p[x.S - 1]]] && (posa[x.S - 1] >= maxi[p[x.S - 1]]);
}
else{
ok[x.S - 1] = true;
}
}
f(i,0,n){
cout<<ok[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
123 ms |
22412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
134 ms |
22420 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |