#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>sum && k!=-(*values.begin()))
continue;
for (auto x : nodes)
possible[x]=true;
}
}
for (int i=0; i<n; i++)
cout << possible[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7260 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Correct |
1 ms |
7260 KB |
Output is correct |
4 |
Correct |
15 ms |
7640 KB |
Output is correct |
5 |
Correct |
5 ms |
7696 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
12 ms |
7660 KB |
Output is correct |
8 |
Correct |
12 ms |
7648 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
4 ms |
7512 KB |
Output is correct |
12 |
Correct |
4 ms |
7616 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
4 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7260 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Execution timed out |
1088 ms |
24312 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7260 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
24080 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7260 KB |
Output is correct |
2 |
Correct |
86 ms |
15212 KB |
Output is correct |
3 |
Correct |
90 ms |
19536 KB |
Output is correct |
4 |
Correct |
92 ms |
19720 KB |
Output is correct |
5 |
Correct |
62 ms |
20348 KB |
Output is correct |
6 |
Correct |
55 ms |
19916 KB |
Output is correct |
7 |
Correct |
50 ms |
22148 KB |
Output is correct |
8 |
Correct |
45 ms |
19008 KB |
Output is correct |
9 |
Correct |
55 ms |
15188 KB |
Output is correct |
10 |
Correct |
56 ms |
18892 KB |
Output is correct |
11 |
Correct |
90 ms |
18140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7260 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Correct |
1 ms |
7260 KB |
Output is correct |
4 |
Correct |
15 ms |
7640 KB |
Output is correct |
5 |
Correct |
5 ms |
7696 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
12 ms |
7660 KB |
Output is correct |
8 |
Correct |
12 ms |
7648 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
4 ms |
7512 KB |
Output is correct |
12 |
Correct |
4 ms |
7616 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
4 ms |
7516 KB |
Output is correct |
15 |
Correct |
1 ms |
7260 KB |
Output is correct |
16 |
Correct |
1 ms |
7260 KB |
Output is correct |
17 |
Execution timed out |
1088 ms |
24312 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |