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"
#define intt long long
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<intt,intt>
#define ld long double
using namespace std;
const int sz = 2e5+5;
int a[sz];
vector<int>g[sz];
set<int>s;
int used[sz];
string res;
intt dfs(int node, int mx){
used[node] = mx;
intt res = a[node];
for ( int i : g[node] ){
if ( a[i] < mx and used[i] != mx ) res += dfs(i, mx);
}
return res;
}
void fill(int node, int mx){
res[node-1] = '0';
for ( int i : g[node] ){
if ( a[i] < mx and res[i-1] == '1' ){
fill(i, mx);
}
}
}
int i,j;
int main(){
int n, m;
cin >> n >> m;
res.resize(n, '1');
for ( i = 1; i <= n; i++ ){
cin >> a[i];
s.insert(a[i]);
}
for ( i = 1; i <= m; i++ ){
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
while (!s.empty()){
int mx = *s.rbegin();
s.erase(mx);
for ( i = 1; i <= n; i++ ){
if ( a[i] < mx and res[i-1] == '1' and used[i] != mx and dfs(i, mx) < 1LL*mx ){
fill(i, mx);
}
}
}
cout << res << endl;
}
/*
4 3
4 2 2 1
1 2
3 2
4 1
*/
# | 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... |