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>
#pragma GCC optimize("Ofast")
using namespace std;
int N;
vector<vector<int>> adj;
vector<int> cnt;
vector<bool> vis;
int curr = 0;
void dfs(int pos) {
vis[pos] = true;
curr += cnt[pos];
for (auto &v: adj[pos]) {
if (vis[v] || cnt[v] > curr) continue;
dfs(v);
}
}
bool comp(int a, int b) {
return cnt[a] < cnt[b];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int M;
cin >> N >> M;
cnt.resize(N + 1);
for (int i = 1; i <= N; i++) cin >> cnt[i];
adj.resize(N + 1);
for (int i = 0, u, v; i < M; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= N; i++) {
sort(adj[i].begin(), adj[i].end(), comp);
}
string res;
vis.resize(N + 1);
for (int i = 1; i <= N; i++) {
fill(vis.begin(), vis.end(), false);
curr = 0;
dfs(i);
bool ok = true;
for (int i = 1; i <= N; i++) {
if (!vis[i]) {
ok = false;
break;
}
}
res.push_back((ok ? '1' : '0'));
}
cout << res;
return 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... |