#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
using namespace std;
const int MAX_N = 2e5 + 9;
vector<int> adj[MAX_N], weights(MAX_N, 0);
bool visited[MAX_N];
priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
void add_children(int u){
for(int i: adj[u]){
if(visited[i]) continue;
visited[i] = 1;
pq.push(make_pair(weights[i], i));
}
}
signed main() {
int n, m, right = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> weights[i];
right += weights[i];
}
for(int i = 0; i < m; i++){
int x, y;
cin >> x >> y;
adj[y].push_back(x);
adj[x].push_back(y);
}
for(int i = 1; i <= n; i++){
int sum = weights[i];
visited[i] = 1;
add_children(i);
while(!pq.empty() && pq.top().ff <= sum){
sum += pq.top().ff;
int u = pq.top().ss;
pq.pop();
add_children(u);
}
bool ok = true;
for(int i = 1; i <= n; i++){
if(!visited[i]){
ok = false;
break;
}
}
cout << ok;
pq = priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>();
fill(visited, visited + MAX_N, false);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
Output is correct |
2 |
Correct |
4 ms |
6740 KB |
Output is correct |
3 |
Correct |
4 ms |
6740 KB |
Output is correct |
4 |
Correct |
177 ms |
6740 KB |
Output is correct |
5 |
Correct |
172 ms |
6740 KB |
Output is correct |
6 |
Correct |
217 ms |
6740 KB |
Output is correct |
7 |
Correct |
165 ms |
6740 KB |
Output is correct |
8 |
Correct |
125 ms |
6740 KB |
Output is correct |
9 |
Incorrect |
230 ms |
6868 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
Output is correct |
2 |
Correct |
4 ms |
6740 KB |
Output is correct |
3 |
Execution timed out |
1074 ms |
15180 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
Output is correct |
2 |
Execution timed out |
1061 ms |
12944 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
14420 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
Output is correct |
2 |
Correct |
4 ms |
6740 KB |
Output is correct |
3 |
Correct |
4 ms |
6740 KB |
Output is correct |
4 |
Correct |
177 ms |
6740 KB |
Output is correct |
5 |
Correct |
172 ms |
6740 KB |
Output is correct |
6 |
Correct |
217 ms |
6740 KB |
Output is correct |
7 |
Correct |
165 ms |
6740 KB |
Output is correct |
8 |
Correct |
125 ms |
6740 KB |
Output is correct |
9 |
Incorrect |
230 ms |
6868 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |