This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <set>
#include <algorithm>
#include <vector>
#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double pd;
ll n, m;
ll s[maxn];
set <ll> v[maxn];
pii sorted[maxn];
void read()
{
cin >> n >> m;
for(ll i = 1; i <= n; i++)
cin >> s[i];
for(ll i = 1; i <= n; i++)
sorted[i] = {s[i], i};
ll x, y;
for(ll i = 1; i <= m; i++)
{
cin >> x >> y;
v[x].insert(y);
v[y].insert(x);
}
sort(sorted + 1, sorted + 1 + n);
/**for(ll i = 1; i <= n; i++)
cout << sorted[i].X << " " << sorted[i].Y << endl;*/
}
ll par[maxn], sz[maxn], sum[maxn];
bool lamp[maxn];
set <ll> nodes[maxn];
ll f(ll node)
{
return node == par[node]? node : par[node] = f(par[node]);
}
void unite(ll a, ll b)
{
a = f(a);
b = f(b);
if(a == b)
return;
if(sz[b] > sz[a])
swap(a, b);
for(auto e : nodes[b])
nodes[a].insert(e);
sum[a] += sum[b];
par[b] = a;
sz[a] += sz[b];
}
void solve()
{
for(ll i = 1; i <= n; i++)
{
nodes[i].clear();
par[i] = i;
sz[i] = 1;
lamp[i] = false;
sum[i] = 0;
}
for(ll i = 1; i <= n; i++)
{
ll curr = sorted[i].Y;
//cout << curr << endl;
vector <ll> act;
for(auto e : v[curr])
if(lamp[e] == true)
act.pb(f(e));
lamp[curr] = true;
nodes[curr].insert(curr);
sum[curr] = s[curr];
for(auto e : act)
if(s[curr] > sum[e])
{
nodes[e].clear();
unite(e, curr);
}
for(auto e : act)
unite(e , curr);
}
for(ll i = 1; i <= n; i++)
{
ll a = f(1);
auto p1 = nodes[a].find(i);
if(p1 == nodes[a].end())
cout << '0';
else
cout << '1';
}
}
int main()
{
/**#ifdef ONLINE_JUDGE /// promeni
freopen("taxi.in", "r", stdin);
freopen("taxi.out", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
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... |