#include <bits/stdc++.h>
using namespace std;
const int MAXN=300000, INF=2e9;
// 2e5 ??
int n, m;
int a[MAXN];
vector<int> adj[MAXN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; i++)
cin >> a[i];
for (int i=0; i<m; i++)
{
int x, y;
cin >> x >> y;
adj[x-1].push_back(y-1);
adj[y-1].push_back(x-1);
}
set<int> values;
for (int i=0; i<n; i++)
values.insert(-a[i]);
bool possible[n]={false};
queue<int> q;
for (auto kt : values)
{
int k=-kt;
bool visited[n]={false};
for (int i=0; i<n; i++)
{
if (a[i]!=k || visited[i])
continue;
visited[i]=true;
long long sum=a[i];
q.push(i);
vector<int> nodes;
nodes.push_back(i);
int minsum=INF;
while (!q.empty())
{
int x=q.front();
q.pop();
for (auto y : adj[x])
{
if (a[y]<=k && !visited[y])
{
visited[y]=true;
sum=sum+a[y];
q.push(y);
if (a[y]==k)
nodes.push_back(y);
}
if (a[y]>k && possible[y])
minsum=min(minsum, a[y]);
}
}
if (minsum!=INF && minsum>sum)
continue;
for (auto x : nodes)
possible[x]=true;
}
}
for (int i=0; i<n; i++)
cout << possible[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7516 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
1 ms |
7512 KB |
Output is correct |
4 |
Incorrect |
15 ms |
7688 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7260 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Execution timed out |
1095 ms |
28740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
28456 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
86 ms |
19536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7516 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
1 ms |
7512 KB |
Output is correct |
4 |
Incorrect |
15 ms |
7688 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |