#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int s[200005];
vector<pair<int,int>> e;
bool ok[200005];
int t[200005],sum[200005];
vector<int> l[200005];
int reprezentant(int nod)
{
if(t[nod]==nod)
{
return nod;
}
return reprezentant(t[nod]);
}
void uneste(int x, int y)
{
x = reprezentant(x);
y = reprezentant(y);
if(x==y)
{
return;
}
if(l[x].size() > l[y].size())
{
sum[x] += sum[y];
t[y] = x;
for(auto it : l[y])
{
l[x].push_back(it);
}
}
else
{
sum[y] += sum[x];
t[x] = y;
for(auto it : l[x])
{
l[y].push_back(it);
}
}
}
bool cmp(pair<int,int> a, pair<int,int> b)
{
return (max(s[a.first],s[a.second]) < max(s[b.first],s[b.second]) || (max(s[a.first],s[a.second]) == max(s[b.first],s[b.second]) && min(s[a.first],s[a.second]) < min(s[b.first],s[b.second])));
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++)
{
cin>>s[i];
}
for(int i=1; i<=m; i++)
{
int x,y;
cin>>x>>y;
e.push_back({x,y});
}
for(int i=1; i<=n; i++)
{
t[i] = i;
l[i].push_back(i);
sum[i] = s[i];
ok[i] = true;
}
sort(e.begin(),e.end(),cmp);
for(auto it : e)
{
int x = it.first;
int y = it.second;
if(s[x] > s[y])
{
swap(x,y);
}
if(sum[reprezentant(x)] >= s[y])
{
uneste(x,y);
}
else
{
for(auto it : l[x])
{
ok[it] = false;
}
}
}
for(int i=1; i<=n; i++)
{
cout<<ok[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5032 KB |
Output is correct |
3 |
Correct |
3 ms |
5044 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5180 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Incorrect |
107 ms |
25552 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
145 ms |
23820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
156 ms |
24316 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5032 KB |
Output is correct |
3 |
Correct |
3 ms |
5044 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5180 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |