#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 2e5+3;
int i,j,p,q,n,m,k;
vector <int> s[maxn];
int par[maxn],num[maxn],sum[maxn];
vector <int> v[maxn];
vector <pair<int,int>> g[maxn];
pair <int,int> obh[maxn];
bool covered[maxn];
int Find(int p)
{
if(par[p]==p)
return p;
return Find(par[p]);
}
void Union(int p,int q)
{
p = Find(p);
q = Find(q);
if(s[p].size()<s[q].size())
swap(p,q);
par[q] = p;
sum[p] += sum[q];
for(auto jj:s[q])
s[p].push_back(jj);
v[q].clear();//reserve
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
vector <char> c(n);
for(i=1;i<=n;i++)
{
cin>>num[i];
obh[i] = {num[i],i};
}
sort(obh+1,obh+n+1);
for(i=1;i<=m;i++)
{
cin>>p>>q;
g[p].push_back({num[q],q});
g[q].push_back({num[p],p});
}
for(i=1;i<=n;i++)
{
sort(g[i].begin(),g[i].end());
for(auto j:g[i])
v[i].push_back(j.second);
}
for(i=1;i<=n;i++)
{
par[i] = i;
sum[i] = num[i];
s[i].push_back(i);
}
for(i=1;i<=n;i++)
{
p = obh[i].second;
covered[p] = true;
k = Find(p);
for(auto j:v[p])
{
int pp = Find(j);
if(pp==k || covered[j])continue;
// cout<<j<<endl;
if(num[j]>sum[p])///can't proceed further
{
s[k].clear();
}
Union(k,pp);
}
}
p = Find(1);
for(i=0;i<n;i++)
c[i] = '0';
for(auto i:s[p])
c[i-1] = '1';
for(auto i:c)
cout<<i;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14432 KB |
Output is correct |
3 |
Correct |
9 ms |
14408 KB |
Output is correct |
4 |
Incorrect |
10 ms |
14608 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14436 KB |
Output is correct |
2 |
Correct |
8 ms |
14332 KB |
Output is correct |
3 |
Incorrect |
166 ms |
42904 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
228 ms |
42264 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14428 KB |
Output is correct |
2 |
Incorrect |
265 ms |
43556 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14432 KB |
Output is correct |
3 |
Correct |
9 ms |
14408 KB |
Output is correct |
4 |
Incorrect |
10 ms |
14608 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |