답안 #879465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879465 2023-11-27T13:47:35 Z vladburac Stranded Far From Home (BOI22_island) C++17
100 / 100
271 ms 27216 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NMAX = 2e5;

pair<int, int> v[NMAX+1];
vector <int> edges[NMAX+1];
int parent[NMAX+1];
bool viz[NMAX+1];
int marked[NMAX+1];
ll sum[NMAX+1];

int findd( int x ) { // parintele si daca am marcat pe lant pana la radacina
  if( parent[x] == x )
    return x;
  int sef = findd( parent[x] );
  marked[x] |= marked[parent[x]];
  parent[x] = sef;
  return sef;
}

void unite( int a, int b, int newVal ) {
  int x = findd( a );
  int y = findd( b );
  if( sum[x] < newVal )
    marked[x] = true;
  if( x != y ) {
    parent[x] = y;
    sum[y] += sum[x];
  }
}
void solve() {
  int n, m, i, a, b;
  cin >> n >> m;
  for( i = 0; i < n; i++ ) {
    cin >> v[i].first;
    v[i].second = i;
    parent[i] = i;
    viz[i] = false;
    sum[i] = v[i].first;
  }
  v[n].first = 0;
  for( i = 0; i < m; i++ ) {
    cin >> a >> b;
    a--, b--;
    edges[a].push_back( b );
    edges[b].push_back( a );
  }
  sort( v, v + n );
  for( i = 0; i < n; i++ ) {
    viz[v[i].second] = true;
    for( auto vec: edges[v[i].second] ) {
      if( viz[vec] )
        unite( vec, v[i].second, v[i].first );
    }
  }
  for( i = 0; i < n; i++ )
    a = findd( i );
  for( i = 0; i < n; i++ )
    cout << 1 - marked[i];
  cout << "\n";
}
int main() {
  //ios_base::sync_with_stdio( false );
  //cin.tie( NULL );
  //cout.tie( NULL );
  int t = 1;
  //cin >> t;
  while( t-- )
    solve();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 4 ms 6644 KB Output is correct
7 Correct 3 ms 8728 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 3 ms 8692 KB Output is correct
12 Correct 3 ms 8688 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 185 ms 16252 KB Output is correct
4 Correct 165 ms 22100 KB Output is correct
5 Correct 184 ms 20304 KB Output is correct
6 Correct 189 ms 20852 KB Output is correct
7 Correct 198 ms 20848 KB Output is correct
8 Correct 214 ms 20736 KB Output is correct
9 Correct 181 ms 20564 KB Output is correct
10 Correct 167 ms 20980 KB Output is correct
11 Correct 203 ms 26788 KB Output is correct
12 Correct 167 ms 19492 KB Output is correct
13 Correct 185 ms 25444 KB Output is correct
14 Correct 158 ms 25048 KB Output is correct
15 Correct 226 ms 20824 KB Output is correct
16 Correct 167 ms 20124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 213 ms 16208 KB Output is correct
3 Correct 226 ms 20712 KB Output is correct
4 Correct 237 ms 27112 KB Output is correct
5 Correct 164 ms 23428 KB Output is correct
6 Correct 224 ms 20860 KB Output is correct
7 Correct 198 ms 20796 KB Output is correct
8 Correct 200 ms 20740 KB Output is correct
9 Correct 164 ms 20244 KB Output is correct
10 Correct 181 ms 23124 KB Output is correct
11 Correct 176 ms 20544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 247 ms 16540 KB Output is correct
3 Correct 211 ms 20820 KB Output is correct
4 Correct 215 ms 20964 KB Output is correct
5 Correct 207 ms 20816 KB Output is correct
6 Correct 189 ms 20312 KB Output is correct
7 Correct 180 ms 23668 KB Output is correct
8 Correct 153 ms 22684 KB Output is correct
9 Correct 158 ms 15860 KB Output is correct
10 Correct 159 ms 19284 KB Output is correct
11 Correct 183 ms 20440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 4 ms 6644 KB Output is correct
7 Correct 3 ms 8728 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 3 ms 8692 KB Output is correct
12 Correct 3 ms 8688 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 185 ms 16252 KB Output is correct
18 Correct 165 ms 22100 KB Output is correct
19 Correct 184 ms 20304 KB Output is correct
20 Correct 189 ms 20852 KB Output is correct
21 Correct 198 ms 20848 KB Output is correct
22 Correct 214 ms 20736 KB Output is correct
23 Correct 181 ms 20564 KB Output is correct
24 Correct 167 ms 20980 KB Output is correct
25 Correct 203 ms 26788 KB Output is correct
26 Correct 167 ms 19492 KB Output is correct
27 Correct 185 ms 25444 KB Output is correct
28 Correct 158 ms 25048 KB Output is correct
29 Correct 226 ms 20824 KB Output is correct
30 Correct 167 ms 20124 KB Output is correct
31 Correct 2 ms 6488 KB Output is correct
32 Correct 213 ms 16208 KB Output is correct
33 Correct 226 ms 20712 KB Output is correct
34 Correct 237 ms 27112 KB Output is correct
35 Correct 164 ms 23428 KB Output is correct
36 Correct 224 ms 20860 KB Output is correct
37 Correct 198 ms 20796 KB Output is correct
38 Correct 200 ms 20740 KB Output is correct
39 Correct 164 ms 20244 KB Output is correct
40 Correct 181 ms 23124 KB Output is correct
41 Correct 176 ms 20544 KB Output is correct
42 Correct 1 ms 6488 KB Output is correct
43 Correct 247 ms 16540 KB Output is correct
44 Correct 211 ms 20820 KB Output is correct
45 Correct 215 ms 20964 KB Output is correct
46 Correct 207 ms 20816 KB Output is correct
47 Correct 189 ms 20312 KB Output is correct
48 Correct 180 ms 23668 KB Output is correct
49 Correct 153 ms 22684 KB Output is correct
50 Correct 158 ms 15860 KB Output is correct
51 Correct 159 ms 19284 KB Output is correct
52 Correct 183 ms 20440 KB Output is correct
53 Correct 1 ms 6700 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 3 ms 8536 KB Output is correct
57 Correct 3 ms 8540 KB Output is correct
58 Correct 4 ms 6704 KB Output is correct
59 Correct 3 ms 8540 KB Output is correct
60 Correct 3 ms 8540 KB Output is correct
61 Correct 2 ms 6748 KB Output is correct
62 Correct 3 ms 8540 KB Output is correct
63 Correct 3 ms 8660 KB Output is correct
64 Correct 3 ms 8536 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 3 ms 6712 KB Output is correct
67 Correct 195 ms 20736 KB Output is correct
68 Correct 158 ms 21960 KB Output is correct
69 Correct 211 ms 20448 KB Output is correct
70 Correct 194 ms 20676 KB Output is correct
71 Correct 200 ms 20824 KB Output is correct
72 Correct 271 ms 20912 KB Output is correct
73 Correct 183 ms 20724 KB Output is correct
74 Correct 187 ms 20768 KB Output is correct
75 Correct 188 ms 27180 KB Output is correct
76 Correct 162 ms 19312 KB Output is correct
77 Correct 152 ms 25424 KB Output is correct
78 Correct 160 ms 25164 KB Output is correct
79 Correct 178 ms 20880 KB Output is correct
80 Correct 162 ms 20052 KB Output is correct
81 Correct 234 ms 20644 KB Output is correct
82 Correct 242 ms 20916 KB Output is correct
83 Correct 204 ms 27216 KB Output is correct
84 Correct 173 ms 23844 KB Output is correct
85 Correct 204 ms 20700 KB Output is correct
86 Correct 207 ms 20812 KB Output is correct
87 Correct 227 ms 20852 KB Output is correct
88 Correct 189 ms 23292 KB Output is correct
89 Correct 176 ms 20564 KB Output is correct
90 Correct 224 ms 20792 KB Output is correct
91 Correct 217 ms 20852 KB Output is correct
92 Correct 236 ms 20768 KB Output is correct
93 Correct 212 ms 20816 KB Output is correct
94 Correct 197 ms 20260 KB Output is correct
95 Correct 223 ms 23836 KB Output is correct
96 Correct 171 ms 22868 KB Output is correct
97 Correct 141 ms 15852 KB Output is correct
98 Correct 173 ms 19204 KB Output is correct
99 Correct 187 ms 20448 KB Output is correct
100 Correct 86 ms 12772 KB Output is correct
101 Correct 265 ms 20772 KB Output is correct
102 Correct 197 ms 18772 KB Output is correct
103 Correct 226 ms 19280 KB Output is correct
104 Correct 234 ms 20572 KB Output is correct