#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long maxn = 2e5+3;
long long i,j,p,q,n,m,k;
vector <long long> s[maxn];
long long par[maxn],num[maxn],sum[maxn];
vector <long long> v[maxn];
vector <pair<long long,long long>> g[maxn];
pair <long long,long long> obh[maxn];
bool covered[maxn];
long long Find(long long p)
{
if(par[p]==p)
return p;
return Find(par[p]);
}
void Union(long long p,long long 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);
s[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])
{
long long pp = Find(j);
if(pp==k || covered[j])continue;
// cout<<j<<endl;
if(num[j]>sum[k])///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 |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14716 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14424 KB |
Output is correct |
3 |
Correct |
217 ms |
48776 KB |
Output is correct |
4 |
Incorrect |
213 ms |
51316 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
263 ms |
54604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Runtime error |
251 ms |
98688 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14716 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |