이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
}
}
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;
if(s[x]>=s[y])
{
e.push_back({x,y});
}
else
{
e.push_back({y,x});
}
}
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());
for(auto it : e)
{
int x = it.first;
int y = it.second;
swap(x,y);
if(sum[reprezentant(x)] >= s[y])
{
uneste(x,y);
}
else
{
for(auto it2 : l[reprezentant(x)])
{
ok[it2] = false;
}
}
}
for(int i=1; i<=n; i++)
{
cout<<ok[i];
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |