#include <bits/stdc++.h>
using namespace std;
#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef vector<vi> vvi;
typedef priority_queue<int> pq;
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
const int inf = 1e17;
struct ufds {
vi par;
ufds(int n) : par(n, -1) {};
ufds(vi a) : par(a) {
for(int i = 0; i < par.size(); i++)
par[i] = -par[i];
};
int find(int u) {
if(par[u] < 0) return u;
return par[u] = find(par[u]);
}
int size(int u) {
return -par[find(u)];
}
bool merge(int u, int v) {
u = find(u);
v = find(v);
if(u == v) return false;
//if(size(u) < size(v)) swap(u, v);
par[u] += par[v];
par[v] = u;
return true;
}
};
void solve() {
int n, m;
cin >> n >> m;
vi s(n+1);
vii ss(n+1);
vi adj[n+1];
loop1(i, n)
cin >> s[i];
loop1(i, n)
ss[i] = {s[i], i};
sort(all1(ss));
loop1(i, m) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
vb incl(n+1);
ufds ufds(s);
vb valid(n+1, true);
loop1(i, n) {
auto [su, u] = ss[i];
incl[u] = true;
for(auto v : adj[u]) if(incl[v]) {
if(ufds.find(u) != ufds.find(v)) {
if(ufds.size(v) < ufds.size(u)) {
loop1(i, n) {
if(ufds.find(i) == ufds.find(v))
valid[i] = false;
}
}
ufds.merge(u, v);
}
}
}
loop1(i, n) cout << valid[i];
cout << endl;
}
signed main() {
fast_io;
int t = 1; //cin >> t;
while(t--)
solve();
return 0;
}
Compilation message
island.cpp: In constructor 'ufds::ufds(vi)':
island.cpp:40:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < par.size(); i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
6 ms |
432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
24548 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
23336 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1074 ms |
24484 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
6 ms |
432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |