#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
struct DSU {
int n;
vector<ll> fa;
vector<ll> cnt;
vector<ll> del;
DSU(int _n,vector<pll> &w):n(_n) {
fa.resize(n+1);
cnt.resize(n+1);
del.resize(n+1);
for (int i=0;i<n;i++) {
cnt[w[i].S]=w[i].F;
}
iota(all(fa),0);
}
pll get(ll x) {
if (fa[x]==x) return {del[x],x};
else {
pll ret = get(fa[x]);
del[x]|=ret.F;
fa[x]=ret.S;
return {del[x]|ret.F,ret.S};
}
}
void unionn(int a,int b) {
a=get(a).S;b=get(b).S;
if (a==b) return;
fa[a]=b;
cnt[b]+=cnt[a];
}
};
int main() {
speed;
int n,m;
cin>>n>>m;
vvector<ll> G(n+1);
vector<pll> w;
vector<ll> cnt(n+1);
for (int i=1;i<=n;i++) {
cin>>cnt[i];
w.emplace_back(cnt[i],i);
}
sort(all(w));
for (int i=0;i<m;i++) {
ll a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
DSU d(n,w);
for (int i=1;i<n;i++) {
ll v=w[i].S;
for (ll u:G[v]) {
if (cnt[u]>cnt[v]) continue;
ll ru=d.get(u).S;
if (d.cnt[ru]<cnt[v]) d.del[ru]=true;
d.unionn(u,v);
}
}
for (int i=1;i<=n;i++) {
cout<<!(d.del[i]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
92 ms |
22904 KB |
Output is correct |
4 |
Incorrect |
90 ms |
22940 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
139 ms |
21696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
126 ms |
22696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |