Submission #574132

#TimeUsernameProblemLanguageResultExecution timeMemory
574132eecsStranded Far From Home (BOI22_island)C++17
100 / 100
320 ms30880 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, m, a[maxn], fa[maxn], sum[maxn]; bool vis[maxn], ans[maxn]; vector<int> G[maxn], Q[maxn]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> m; vector<array<int, 2>> V; for (int i = 1; i <= n; i++) { cin >> a[i], V.push_back({a[i], i}); } while (m--) { int u, v; cin >> u >> v; G[u].push_back(v), G[v].push_back(u); } sort(V.begin(), V.end()); for (int i = 1; i <= n; i++) { int j = lower_bound(V.begin(), V.end(), array<int, 2>{a[i] + 1, 0}) - V.begin() - 1; Q[j].push_back(i); } iota(fa + 1, fa + n + 1, 1); copy(a + 1, a + n + 1, sum + 1); int lst = 0; for (int i = 0; i < V.size(); i++) { vis[V[i][1]] = 1; for (int j : G[V[i][1]]) if (vis[j]) { int x = find(V[i][1]), y = find(j); if (x ^ y) fa[y] = x, sum[x] = min((int)1e9, sum[x] + sum[y]); } if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue; for (int x : Q[i]) { int y = lower_bound(V.begin(), V.end(), array<int, 2>{sum[find(x)] + 1, 0}) - V.begin() - 1; if (i < y) Q[y].push_back(x); else if (i + 1 == V.size()) ans[x] = 1; } } for (int i = 1; i <= n; i++) { cout << (ans[i] ? '1' : '0'); } return 0; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < V.size(); i++) {
      |                     ~~^~~~~~~~~~
island.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue;
      |             ~~~~~~^~~~~~~~~~
island.cpp:43:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             else if (i + 1 == V.size()) ans[x] = 1;
      |                      ~~~~~~^~~~~~~~~~~
island.cpp:32:9: warning: unused variable 'lst' [-Wunused-variable]
   32 |     int lst = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...