#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 2e5 + 5;
struct comp
{
ll sum = 0;
priority_queue<pair<int, int> > s;
};
vector<comp> c(maxn);
vector<int> a(maxn), p(maxn);
int root(int u)
{
return u == p[u] ? u : p[u] = root(p[u]);
}
int merge(int u, int v)
{
u = root(u), v = root(v);
if (u == v) return u;
if (c[u].s.size() < c[v].s.size()) swap(u, v);
p[v] = u;
c[u].sum += c[v].sum;
while (!c[v].s.empty()) c[u].s.push(c[v].s.top()), c[v].s.pop();
return u;
}
bool cmp(int i, int j)
{
return a[i] < a[j];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int> > w;
for (int i = 0; i < n; i++)
{
cin >> a[i];
w.push_back({ a[i], i });
c[i].sum = a[i];
p[i] = i;
}
vector<vector<int> > g(n);
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
u--, v--;
if (make_pair( a[u], u ) > make_pair( a[v], v )) swap(u, v);
c[u].s.push({-a[v], v});
g[v].push_back(u);
}
vector<int> de(n, -1);
sort(w.begin(), w.end());
for (pair<int, int> p : w)
{
int u = p.second, cm = u;
for (int v : g[u]) cm = merge(cm, v);
while (!c[cm].s.empty() && c[cm].s.top().second == u) c[cm].s.pop();
if (!c[cm].s.empty() && a[c[cm].s.top().second] <= c[cm].sum) de[u] = c[cm].s.top().second;
}
reverse(w.begin(), w.end());
vector<bool> ans(n, false);
for (pair<int, int> p : w)
{
int u = p.second;
if (p == w[0]) ans[u] = true;
else if (de[u] != -1) ans[u] = ans[de[u]];
}
for (int i = 0; i < n; i++) cout << "01"[ans[i]];
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9856 KB |
Output is correct |
5 |
Incorrect |
6 ms |
9812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9648 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
227 ms |
29624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
233 ms |
27104 KB |
Output is correct |
3 |
Incorrect |
268 ms |
27256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
282 ms |
31172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9856 KB |
Output is correct |
5 |
Incorrect |
6 ms |
9812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |