/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
#include <functional>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
const LL mod = 1e9 + 7, inf = 1e18;
vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };
void solve() {
int n, m; cin >> n >> m;
vector<int> s(n);
map<int, vector<int>> srt;
for(int i = 0; i < n; ++i){
cin >> s[i];
srt[s[i]].push_back(i);
}
vector<int> t = s;
sort(t.begin(), t.end());
vector<vector<int>> gp(n);
for(int i = 0; i < m; ++i){
int u, v; cin >> u >> v;
gp[--u].push_back(--v);
gp[v].push_back(u);
}
vector<LL> par(n), sz(n), sizes(n, 1);
for(int i = 0; i < n; ++i){
par[i] = i;
sz[i] = s[i];
}
string ans(n, '1');
function<int(int)> get = [&](int u){
if(par[u] == u) return u;
return get(par[u]);
};
function<void(int u, int v)> unions = [&](int u, int v){
int a = get(u), b = get(v);
if(a == b) return;
par[b] = a;
sizes[a] += sizes[b];
sz[a] += sz[b];
};
function<bool(int)> check = [&](int u){
if(ans[u] == '0') return false;
if(par[u] == u) return true;
return check(par[u]);
};
for(auto x : srt){
vector<int> nodes = x.second;
int cnt = x.first;
int nxt = upper_bound(t.begin(), t.end(), cnt) - t.begin();
if(nxt == t.size()) continue;
nxt = t[nxt];
for(int &u : nodes) {
for(int &v : gp[u]){
if(s[v] <= s[u]){
unions(u, v);
}
}
}
for(int &u : nodes){
if(sz[get(u)] < nxt){
ans[u] = '0';
}
}
}
for(int i = 0; i < n; ++i){
cout << check(i);
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t; while (t--)
solve();
}
Compilation message
island.cpp: In function 'void solve()':
island.cpp:86:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | if(nxt == t.size()) continue;
| ~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
5 ms |
584 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 |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1089 ms |
44656 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 |
Incorrect |
430 ms |
43940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
261 ms |
23396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
5 ms |
584 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |