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;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int s[N];
vector<int> g[N];
bool can[N];
vector<int> comp;
int color[N];
void dfs(int v){
color[v] = 2;
comp.push_back(v);
for (int u : g[v]){
if (!can[u] && color[u] == 1){
dfs(u);
}
}
}
void go(vector<int> &vertices, long long need){
long long sum = 0;
int mx = 0;
for (int v : vertices){
sum += s[v];
mx = max(mx, s[v]);
color[v] = 1;
}
if (sum < need) return;
for (int v : vertices){
if (s[v] == mx) can[v] = true;
}
vector<vector<int>> components;
for (int v : vertices){
if (color[v] == 1 && !can[v]){
comp.clear();
dfs(v);
components.push_back(comp);
}
}
for (auto vec : components){
go(vec, mx);
}
}
void solve(){
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
}
while (m--){
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
ll total = accumulate(s, s + n, 0ll);
vector<int> vertices(n);
iota(all(vertices), 0);
go(vertices, total);
for (int i = 0; i < n; i++){
cout << can[i];
}
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
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... |