#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
const int MAX_N = 2e6 + 9;
vector<int> adj[MAX_N], weights;
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;
pq.push(make_pair(weights[i], i));
}
}
int main() {
int n, m, right = 0;
cin >> n >> m;
weights.resize(n + 1);
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.top().ff <= sum && !pq.empty()){
visited[pq.top().ss] = 1;
sum += pq.top().ff;
pq.pop();
add_children(pq.top().ss);
}
cout << (sum == right);
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 |
24 ms |
49100 KB |
Output is correct |
2 |
Correct |
24 ms |
49108 KB |
Output is correct |
3 |
Runtime error |
58 ms |
95648 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
49224 KB |
Output is correct |
2 |
Runtime error |
60 ms |
95532 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
95524 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
95532 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
49100 KB |
Output is correct |
2 |
Correct |
24 ms |
49108 KB |
Output is correct |
3 |
Runtime error |
58 ms |
95648 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |