This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, 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 (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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |