#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 |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
2 ms |
6508 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
97 ms |
6748 KB |
Output is correct |
5 |
Correct |
21 ms |
6744 KB |
Output is correct |
6 |
Correct |
6 ms |
6748 KB |
Output is correct |
7 |
Correct |
104 ms |
6920 KB |
Output is correct |
8 |
Correct |
90 ms |
6744 KB |
Output is correct |
9 |
Correct |
4 ms |
6744 KB |
Output is correct |
10 |
Correct |
6 ms |
6748 KB |
Output is correct |
11 |
Correct |
5 ms |
6748 KB |
Output is correct |
12 |
Correct |
5 ms |
6748 KB |
Output is correct |
13 |
Correct |
4 ms |
6744 KB |
Output is correct |
14 |
Correct |
19 ms |
6912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Execution timed out |
1034 ms |
24508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6744 KB |
Output is correct |
2 |
Correct |
391 ms |
21440 KB |
Output is correct |
3 |
Correct |
411 ms |
21440 KB |
Output is correct |
4 |
Execution timed out |
1066 ms |
26992 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6744 KB |
Output is correct |
2 |
Execution timed out |
1097 ms |
22232 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
2 ms |
6508 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
97 ms |
6748 KB |
Output is correct |
5 |
Correct |
21 ms |
6744 KB |
Output is correct |
6 |
Correct |
6 ms |
6748 KB |
Output is correct |
7 |
Correct |
104 ms |
6920 KB |
Output is correct |
8 |
Correct |
90 ms |
6744 KB |
Output is correct |
9 |
Correct |
4 ms |
6744 KB |
Output is correct |
10 |
Correct |
6 ms |
6748 KB |
Output is correct |
11 |
Correct |
5 ms |
6748 KB |
Output is correct |
12 |
Correct |
5 ms |
6748 KB |
Output is correct |
13 |
Correct |
4 ms |
6744 KB |
Output is correct |
14 |
Correct |
19 ms |
6912 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Execution timed out |
1034 ms |
24508 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |