Submission #654463

# Submission time Handle Problem Language Result Execution time Memory
654463 2022-10-31T11:18:42 Z cadmiumsky Stranded Far From Home (BOI22_island) C++14
100 / 100
426 ms 47340 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
const ll inf = 1e18 + 5, nmax = 2e5 + 5;

//#define int ll
//#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

int rez[nmax];

namespace Tree {
  struct Node {
    ll limit; int value, id; ll area = 0; int sz = 0;
    Node(int i, int here, int dim): limit(inf), value(here), id(i), area(here), sz(dim) {;}
  };
  int root;
  vector<Node> atr;
  vector<vector<int>> g;
  int addnew(int area = 0, int val = -1, int dim = 0) {
    root = atr.size();
    atr.emplace_back(val, area, dim);
    g.emplace_back();
    return root;
  }
  
  void addedge(int a, int b) {
    g[a].push_back(b);
    
  }
  
  void initdfs(int node = root) {
    for(auto x : g[node]) {
      initdfs(x);
      atr[node].area += atr[x].area;
      atr[node].sz += atr[x].sz;
    }
    return;
  }
  void dfs(int node = root, int highest = atr[root].sz) {
    if(atr[node].area < atr[node].limit)
      highest = atr[node].sz;
    //cerr << node << ' ' << highest << '\n';
    if(atr[node].id != -1)
      rez[atr[node].id] = highest;
    for(auto x : g[node]) {
      dfs(x, highest);
    }
  }
}

namespace DSU {
  int dsu[nmax * 2];
  void init(int n) {
    for(int i = 0; i < 2 * n; i++) {
      dsu[i] = i;
    }
  }
  int f(int x) { return (dsu[x] == x? x : f(dsu[x] = f(dsu[dsu[x]]))); }
  void unite(int cost, int a, int b) {
    //cerr << a << ' ' << b << ' ' << cost << '\n';
    a = f(a);
    b = f(b);
    if(a == b)
      return;
    int nv = Tree::addnew();
    dsu[a] = nv;
    dsu[b] = nv;
    Tree::addedge(nv, a);
    Tree::addedge(nv, b);
    Tree::atr[a].limit = cost;
    Tree::atr[b].limit = cost;
    //cerr << nv << '\n';
    
  }
}

//using namespace Tree;
int cost[nmax];
vector<tii> edg;

signed main() {
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i++) {
    cin >> cost[i];
    Tree::addnew(cost[i], i, 1);
  }
  
  //assert(m == n - 1);
  for(int x, y, j = 0; j < m; j++) {
    cin >> x >> y;
    --x;
    --y;
    edg.emplace_back(max(cost[x], cost[y]), x, y);
  }
  sort(all(edg));
  DSU::init(n);
  for(auto [cost, a, b] : edg) {
    DSU::unite(cost, a, b);
  }
  Tree::initdfs();
  Tree::dfs();
  for(int i = 0; i < n; i++) {
    cout << (rez[i] == n);
  }
  cout << '\n';
}

/**
      Când iar începe-a ninge
      Mă simt de-un dor cuprins.
      Mă văd, pe-un drum, departe,
      Mergând, încet, şi nins.

      Sub streşină, cerdacul
      Se-ntunecă mâhnit;
      Stă rezimată-o fată
      De stâlpu-nzăpezit.
-- George Bacovia, Ninge
*/

Compilation message

island.cpp: In function 'int main()':
island.cpp:103:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  103 |   for(auto [cost, a, b] : edg) {
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 4 ms 708 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 3 ms 704 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 266 ms 38868 KB Output is correct
4 Correct 226 ms 42600 KB Output is correct
5 Correct 377 ms 33224 KB Output is correct
6 Correct 374 ms 34096 KB Output is correct
7 Correct 372 ms 34188 KB Output is correct
8 Correct 288 ms 43648 KB Output is correct
9 Correct 309 ms 34160 KB Output is correct
10 Correct 263 ms 43516 KB Output is correct
11 Correct 264 ms 43676 KB Output is correct
12 Correct 307 ms 35940 KB Output is correct
13 Correct 229 ms 43436 KB Output is correct
14 Correct 253 ms 42592 KB Output is correct
15 Correct 268 ms 43552 KB Output is correct
16 Correct 262 ms 43104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 338 ms 33856 KB Output is correct
3 Correct 365 ms 34452 KB Output is correct
4 Correct 278 ms 43692 KB Output is correct
5 Correct 243 ms 40628 KB Output is correct
6 Correct 345 ms 34356 KB Output is correct
7 Correct 297 ms 43704 KB Output is correct
8 Correct 270 ms 43836 KB Output is correct
9 Correct 238 ms 43520 KB Output is correct
10 Correct 288 ms 43856 KB Output is correct
11 Correct 246 ms 37216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 426 ms 34704 KB Output is correct
3 Correct 393 ms 34424 KB Output is correct
4 Correct 420 ms 34524 KB Output is correct
5 Correct 383 ms 34408 KB Output is correct
6 Correct 344 ms 34204 KB Output is correct
7 Correct 272 ms 43820 KB Output is correct
8 Correct 243 ms 43620 KB Output is correct
9 Correct 214 ms 18996 KB Output is correct
10 Correct 350 ms 34320 KB Output is correct
11 Correct 242 ms 37256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 4 ms 708 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 3 ms 704 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 266 ms 38868 KB Output is correct
18 Correct 226 ms 42600 KB Output is correct
19 Correct 377 ms 33224 KB Output is correct
20 Correct 374 ms 34096 KB Output is correct
21 Correct 372 ms 34188 KB Output is correct
22 Correct 288 ms 43648 KB Output is correct
23 Correct 309 ms 34160 KB Output is correct
24 Correct 263 ms 43516 KB Output is correct
25 Correct 264 ms 43676 KB Output is correct
26 Correct 307 ms 35940 KB Output is correct
27 Correct 229 ms 43436 KB Output is correct
28 Correct 253 ms 42592 KB Output is correct
29 Correct 268 ms 43552 KB Output is correct
30 Correct 262 ms 43104 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 338 ms 33856 KB Output is correct
33 Correct 365 ms 34452 KB Output is correct
34 Correct 278 ms 43692 KB Output is correct
35 Correct 243 ms 40628 KB Output is correct
36 Correct 345 ms 34356 KB Output is correct
37 Correct 297 ms 43704 KB Output is correct
38 Correct 270 ms 43836 KB Output is correct
39 Correct 238 ms 43520 KB Output is correct
40 Correct 288 ms 43856 KB Output is correct
41 Correct 246 ms 37216 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 426 ms 34704 KB Output is correct
44 Correct 393 ms 34424 KB Output is correct
45 Correct 420 ms 34524 KB Output is correct
46 Correct 383 ms 34408 KB Output is correct
47 Correct 344 ms 34204 KB Output is correct
48 Correct 272 ms 43820 KB Output is correct
49 Correct 243 ms 43620 KB Output is correct
50 Correct 214 ms 18996 KB Output is correct
51 Correct 350 ms 34320 KB Output is correct
52 Correct 242 ms 37256 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 4 ms 724 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 3 ms 736 KB Output is correct
59 Correct 3 ms 724 KB Output is correct
60 Correct 3 ms 708 KB Output is correct
61 Correct 3 ms 724 KB Output is correct
62 Correct 4 ms 640 KB Output is correct
63 Correct 3 ms 596 KB Output is correct
64 Correct 3 ms 596 KB Output is correct
65 Correct 2 ms 724 KB Output is correct
66 Correct 3 ms 708 KB Output is correct
67 Correct 319 ms 42544 KB Output is correct
68 Correct 246 ms 45644 KB Output is correct
69 Correct 396 ms 36764 KB Output is correct
70 Correct 395 ms 37888 KB Output is correct
71 Correct 403 ms 38008 KB Output is correct
72 Correct 305 ms 47280 KB Output is correct
73 Correct 348 ms 37844 KB Output is correct
74 Correct 256 ms 47144 KB Output is correct
75 Correct 259 ms 46896 KB Output is correct
76 Correct 328 ms 38956 KB Output is correct
77 Correct 259 ms 46416 KB Output is correct
78 Correct 231 ms 45620 KB Output is correct
79 Correct 279 ms 47196 KB Output is correct
80 Correct 286 ms 46756 KB Output is correct
81 Correct 344 ms 37552 KB Output is correct
82 Correct 331 ms 37872 KB Output is correct
83 Correct 287 ms 47264 KB Output is correct
84 Correct 222 ms 43428 KB Output is correct
85 Correct 394 ms 37804 KB Output is correct
86 Correct 276 ms 47204 KB Output is correct
87 Correct 312 ms 47340 KB Output is correct
88 Correct 255 ms 47160 KB Output is correct
89 Correct 249 ms 40092 KB Output is correct
90 Correct 374 ms 38328 KB Output is correct
91 Correct 385 ms 37888 KB Output is correct
92 Correct 390 ms 37900 KB Output is correct
93 Correct 395 ms 37940 KB Output is correct
94 Correct 357 ms 37560 KB Output is correct
95 Correct 292 ms 47272 KB Output is correct
96 Correct 227 ms 46828 KB Output is correct
97 Correct 213 ms 21360 KB Output is correct
98 Correct 341 ms 37024 KB Output is correct
99 Correct 251 ms 40068 KB Output is correct
100 Correct 123 ms 5372 KB Output is correct
101 Correct 369 ms 37980 KB Output is correct
102 Correct 374 ms 34180 KB Output is correct
103 Correct 343 ms 35996 KB Output is correct
104 Correct 404 ms 38936 KB Output is correct