이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define pb push_back
#define fore(i , n) for(int i = 0 ; i<n;i++)
#define forr(i , x , y) for(int i = x ; i <= y; i++)
#define forn(i , x , y) for(int i = x ; i >= y; i--)
const int N = 2e5 + 10;
vector<int> adj[N];
int a[N];
int n , m;
vector<bool> vis(N , 0);
vector<int> ans(N , -1);
priority_queue<pair<int ,int> , vector<pair<int ,int>> , greater<pair<int , int>>> pq;
vector<int> possible;
vector<int> nodes;
void expand(int x)
{
pq = priority_queue<pair<int ,int> , vector<pair<int ,int>> , greater<pair<int , int>>>();
int cur = a[x];
pq.push({cur , x});
possible.clear();
nodes.clear();
while(!pq.empty())
{
auto [val , node] = pq.top();
pq.pop();
if(val == cur)
{
possible.pb(node);
if(ans[node] == 0)
{
for(auto v : nodes)
vis[v] = 0;
ans[x] = 0;
return ;
}
}
if(val > cur)
break;
if(vis[node])
continue;
vis[node] = 1;
nodes.pb(node);
if(node != x)
cur+=val;
if(ans[node] == 1)
{
ans[x] = 1;
for(auto v : nodes)
vis[v] = 0;
return;
}
for(auto u : adj[node])
{
pq.push({a[u] , u});
}
}
bool acc = 1;
if((int)nodes.size() != n)
acc = 0;
for(auto u : nodes)
vis[u] = 0;
if(acc)
{
ans[x] = 1;
for(auto u : possible)
ans[u] = 1;
for(auto u : nodes)
{
if(a[u] != a[x])
break;
ans[u] = 1;
}
}
else
{
for(auto p : nodes)
{
ans[p] = 0;
}
ans[x] = 0;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// n = 2e5 , m = n - 1;
cin>>n>>m;
vector<pair<int ,int>> ve;
// int f[10] = {1 , 2 , 5 , 10 , 20 , 6 , 7 , 18 , 40 , 31};
fore(i , n)
{
// a[i] = f[rand()%10];
cin>>a[i];
ve.pb({a[i] , i});
}
sort(ve.rbegin() , ve.rend());
fore(i , m)
{
int u , v;
// u = i + 2 ;
// v = i + 1;
cin>>u>>v;
u-- , v--;
adj[u].pb(v);
adj[v].pb(u);
}
// int cnt = 0;
for(auto [val , i] : ve)
{
if(ans[i] == -1)
{
expand(i);
}
}
fore(i , n)
{
cout<<ans[i];
}
}
# | 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... |