#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 4;
const int INF = 1e9;
int n, m, a[maxn];
vector<int> adj[maxn], nodes[maxn], vals, myVec[maxn];
struct DisjointSet {
vector<int> par, Rank;
DisjointSet(int n) {
par.resize(n + 4); Rank.resize(n + 4);
for (int i = 1; i <= n; i++)
par[i] = i, Rank[i] = vals[a[i]], myVec[i].pb(i);
}
int find(int x) {
if (x != par[x]) par[x] = find(par[x]);
return par[x];
}
bool join(int u, int v) {
u = find(u); v = find(v);
if (u == v) return u;
if (Rank[u] < Rank[v])
swap(u, v);
Rank[u] += Rank[v];
par[v] = u;
if (myVec[u].size() < myVec[v].size())
swap(myVec[u], myVec[v]);
for (auto it : myVec[v])
myVec[u].pb(it);
myVec[v].clear();
return 1;
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vals.pb(a[i]);
}
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
nodes[a[i]].pb(i);
}
for (int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
if (a[u] == a[v]) {
adj[u].pb(v);
adj[v].pb(u);
}
else {
if (a[u] < a[v]) swap(u, v);
adj[u].pb(v);
}
}
bitset<maxn> res;
res.set();
DisjointSet Dsu(n);
for (int i = 0; i < int(vals.size()); i++) {
for (int u : nodes[i]) {
for (int v : adj[u])
Dsu.join(u, v);
u = Dsu.find(u);
if (i + 1 < int(vals.size()) && Dsu.Rank[u] < vals[i + 1])
for (int v : myVec[u])
res[v] = 0;
}
}
for (int i = 1; i <= n; i++)
cout << res[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14436 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
10 ms |
14548 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14436 KB |
Output is correct |
2 |
Correct |
8 ms |
14436 KB |
Output is correct |
3 |
Execution timed out |
1053 ms |
39272 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14440 KB |
Output is correct |
2 |
Incorrect |
319 ms |
46940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
234 ms |
37388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14436 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
10 ms |
14548 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |