#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2005;
vector<int> adj[N];
int a[N], n, m;
ll sum = 0;
bool possible(int start) {
set<pair<int, int>> s;
vector<bool> vis(n, false);
for(auto x: adj[start]) {
s.insert({a[x], x});
}
ll cnt = a[start];
vis[start] = true;
while(!s.empty()) {
auto it = s.begin();
if(it->first > cnt) break;
cnt += it->first;
int v = it->second;
vis[v] = true;
s.erase(it);
for(auto x: adj[v]) {
if(!vis[x]) {
s.insert({a[x], x});
vis[x] = true;
}
}
}
return cnt == sum;
}
int main() {
cin >> n >> m;
for(int i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
for(int i = 0; i < m; ++i) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 0; i < n; ++i) cout << possible(i);
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
197 ms |
412 KB |
Output is correct |
5 |
Correct |
186 ms |
420 KB |
Output is correct |
6 |
Correct |
274 ms |
460 KB |
Output is correct |
7 |
Correct |
180 ms |
424 KB |
Output is correct |
8 |
Correct |
136 ms |
340 KB |
Output is correct |
9 |
Correct |
286 ms |
476 KB |
Output is correct |
10 |
Correct |
92 ms |
432 KB |
Output is correct |
11 |
Correct |
90 ms |
408 KB |
Output is correct |
12 |
Correct |
123 ms |
432 KB |
Output is correct |
13 |
Correct |
184 ms |
412 KB |
Output is correct |
14 |
Correct |
104 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Runtime error |
6 ms |
468 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
6 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
6 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
197 ms |
412 KB |
Output is correct |
5 |
Correct |
186 ms |
420 KB |
Output is correct |
6 |
Correct |
274 ms |
460 KB |
Output is correct |
7 |
Correct |
180 ms |
424 KB |
Output is correct |
8 |
Correct |
136 ms |
340 KB |
Output is correct |
9 |
Correct |
286 ms |
476 KB |
Output is correct |
10 |
Correct |
92 ms |
432 KB |
Output is correct |
11 |
Correct |
90 ms |
408 KB |
Output is correct |
12 |
Correct |
123 ms |
432 KB |
Output is correct |
13 |
Correct |
184 ms |
412 KB |
Output is correct |
14 |
Correct |
104 ms |
424 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Runtime error |
6 ms |
468 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |