#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> G[200001];
ll cad[200001];
ll maxi=0;
vector<ll> sol;
ll cmc(ll node)
{
priority_queue<pair<ll,ll>> q;
map<ll,ll> mapa;
ll ac=cad[node]; mapa[node]=1;
for(auto i:G[node]){ mapa[i]=1;q.push({-cad[i],i});}
while(!q.empty()&&ac<maxi&&ac>=-q.top().first)
{
ll temp=q.top().second;q.pop();
ac+=cad[temp];
if(sol[temp-1]==1) return 1;
for(auto i:G[temp])
{
if(mapa[i]==0)
{
mapa[i]=1;
q.push({-cad[i],i});
}
}
}
return (ac>=maxi);
}
int main()
{
ll n,m;
cin>>n>>m;
vector<pair<ll,ll>> temp;
for(int i=1; i<=n; i++)
{
cin>>cad[i];
temp.push_back({cad[i],i});
}
sort(temp.begin(),temp.end());
maxi=temp.back().first;
reverse(temp.begin(),temp.end());
for(int i=0; i<m; i++)
{
ll a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
sol.assign(n,0);
for(auto i:temp)
{
sol[i.second-1]=cmc(i.second);
}
for(auto i:sol)
cout<<i;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
4 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
3 ms |
6492 KB |
Output is correct |
9 |
Correct |
547 ms |
6748 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
305 ms |
6764 KB |
Output is correct |
14 |
Correct |
225 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
232 ms |
18856 KB |
Output is correct |
4 |
Execution timed out |
1059 ms |
29880 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
199 ms |
17748 KB |
Output is correct |
3 |
Correct |
188 ms |
17732 KB |
Output is correct |
4 |
Correct |
173 ms |
17848 KB |
Output is correct |
5 |
Execution timed out |
1067 ms |
21592 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
202 ms |
18796 KB |
Output is correct |
3 |
Correct |
194 ms |
18612 KB |
Output is correct |
4 |
Correct |
197 ms |
18872 KB |
Output is correct |
5 |
Correct |
162 ms |
18644 KB |
Output is correct |
6 |
Correct |
148 ms |
18356 KB |
Output is correct |
7 |
Execution timed out |
1079 ms |
37628 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
4 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
3 ms |
6492 KB |
Output is correct |
9 |
Correct |
547 ms |
6748 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
305 ms |
6764 KB |
Output is correct |
14 |
Correct |
225 ms |
6744 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
232 ms |
18856 KB |
Output is correct |
18 |
Execution timed out |
1059 ms |
29880 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |