#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2001;
ll S[maxn];
vector <int> adj[maxn];
bool vis[maxn];
int x = 0;
ll sz = 0;
void dfs(int s) {
if (vis[s])
return;
vis[s] = true;
x++;
set <int> to_vis;
for (auto i : adj[s]) {
if (!vis[i])
to_vis.insert(i);
}
while (!to_vis.empty()) {
set <int> to_rem;
for (auto i : to_vis) {
if (vis[i]) {
to_rem.insert(i);
continue;
}
if (S[i] <= sz) {
sz += S[i];
dfs(i);
to_rem.insert(i);
}
}
if (to_rem.empty())
break;
for (auto i : to_rem)
to_vis.erase(i);
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> S[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
sz = S[i];
dfs(i);
if (x == n)
cout << 1;
else
cout << 0;
fill(vis, vis + n + 1, false);
sz = x = 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
161 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
161 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |