# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029980 | 2024-07-21T15:20:29 Z | hasan2006 | Stranded Far From Home (BOI22_island) | C++17 | 415 ms | 104636 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 5e5 + 9 , mod = 1e9 + 7; ll a[N] , b[N] , dp[N] , c[N] , d[N] , p[N] , sz[N]; vector<int>v[N]; set<int>st[N]; ll get(int x){ return (p[x] == x ? x : get(p[x])); } void join(int x , int y , int k){ x = get(x); y = get(y); if(c[x] >= k){ if(st[x].size() > st[y].size()) swap(st[x] , st[y]); for(auto to : st[x]) st[y].insert(to); } if(x != y){ if(sz[x] > sz[y]) swap( x, y) , swap(st[x] , st[y]); p[x] = y; sz[y] += sz[x]; c[y] += c[x]; } } void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n>>m; vector<pair<int,int>>vc; for(i = 1;i <= n; i++){ cin>>a[i]; p[i] = i , sz[i] = 1, c[i] = a[i] , st[i].insert(i); vc.pb({a[i] , i}); } for(i = 1; i <= m; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); } sort(all(vc)); for(auto o : vc){ x = o.se , y =o.fi; //cout<<x<<" "; d[x] = 1; for(auto to : v[x]) if(get(to) != get(x) && d[to] == 1) join(to , x , y); } for(i = 1; i <= n; i++) cout<<(st[get(i)].find(i) != st[get(i)].end()); } int main(){ TL; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 37464 KB | Output is correct |
2 | Correct | 12 ms | 37464 KB | Output is correct |
3 | Correct | 12 ms | 37468 KB | Output is correct |
4 | Correct | 12 ms | 37844 KB | Output is correct |
5 | Correct | 14 ms | 38000 KB | Output is correct |
6 | Correct | 12 ms | 37720 KB | Output is correct |
7 | Correct | 13 ms | 37720 KB | Output is correct |
8 | Correct | 12 ms | 37724 KB | Output is correct |
9 | Correct | 16 ms | 37720 KB | Output is correct |
10 | Correct | 13 ms | 38028 KB | Output is correct |
11 | Correct | 15 ms | 38028 KB | Output is correct |
12 | Correct | 16 ms | 38040 KB | Output is correct |
13 | Correct | 11 ms | 37720 KB | Output is correct |
14 | Correct | 15 ms | 37976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 37464 KB | Output is correct |
2 | Correct | 10 ms | 37464 KB | Output is correct |
3 | Correct | 160 ms | 74448 KB | Output is correct |
4 | Correct | 173 ms | 73772 KB | Output is correct |
5 | Correct | 243 ms | 84668 KB | Output is correct |
6 | Correct | 254 ms | 87488 KB | Output is correct |
7 | Correct | 233 ms | 86764 KB | Output is correct |
8 | Correct | 163 ms | 75076 KB | Output is correct |
9 | Correct | 213 ms | 96096 KB | Output is correct |
10 | Correct | 118 ms | 65596 KB | Output is correct |
11 | Correct | 201 ms | 74688 KB | Output is correct |
12 | Correct | 250 ms | 72744 KB | Output is correct |
13 | Correct | 159 ms | 73408 KB | Output is correct |
14 | Correct | 180 ms | 73640 KB | Output is correct |
15 | Correct | 186 ms | 75068 KB | Output is correct |
16 | Correct | 175 ms | 73916 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 37464 KB | Output is correct |
2 | Correct | 280 ms | 94800 KB | Output is correct |
3 | Correct | 261 ms | 94120 KB | Output is correct |
4 | Correct | 245 ms | 75052 KB | Output is correct |
5 | Correct | 157 ms | 73464 KB | Output is correct |
6 | Correct | 264 ms | 93596 KB | Output is correct |
7 | Correct | 229 ms | 74944 KB | Output is correct |
8 | Correct | 247 ms | 74912 KB | Output is correct |
9 | Correct | 164 ms | 73972 KB | Output is correct |
10 | Correct | 147 ms | 69704 KB | Output is correct |
11 | Correct | 159 ms | 75712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 37608 KB | Output is correct |
2 | Correct | 302 ms | 79984 KB | Output is correct |
3 | Correct | 291 ms | 83136 KB | Output is correct |
4 | Correct | 338 ms | 90408 KB | Output is correct |
5 | Correct | 386 ms | 100048 KB | Output is correct |
6 | Correct | 337 ms | 85692 KB | Output is correct |
7 | Correct | 237 ms | 75308 KB | Output is correct |
8 | Correct | 145 ms | 73404 KB | Output is correct |
9 | Correct | 164 ms | 57588 KB | Output is correct |
10 | Correct | 414 ms | 104192 KB | Output is correct |
11 | Correct | 166 ms | 75152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 37464 KB | Output is correct |
2 | Correct | 12 ms | 37464 KB | Output is correct |
3 | Correct | 12 ms | 37468 KB | Output is correct |
4 | Correct | 12 ms | 37844 KB | Output is correct |
5 | Correct | 14 ms | 38000 KB | Output is correct |
6 | Correct | 12 ms | 37720 KB | Output is correct |
7 | Correct | 13 ms | 37720 KB | Output is correct |
8 | Correct | 12 ms | 37724 KB | Output is correct |
9 | Correct | 16 ms | 37720 KB | Output is correct |
10 | Correct | 13 ms | 38028 KB | Output is correct |
11 | Correct | 15 ms | 38028 KB | Output is correct |
12 | Correct | 16 ms | 38040 KB | Output is correct |
13 | Correct | 11 ms | 37720 KB | Output is correct |
14 | Correct | 15 ms | 37976 KB | Output is correct |
15 | Correct | 13 ms | 37464 KB | Output is correct |
16 | Correct | 10 ms | 37464 KB | Output is correct |
17 | Correct | 160 ms | 74448 KB | Output is correct |
18 | Correct | 173 ms | 73772 KB | Output is correct |
19 | Correct | 243 ms | 84668 KB | Output is correct |
20 | Correct | 254 ms | 87488 KB | Output is correct |
21 | Correct | 233 ms | 86764 KB | Output is correct |
22 | Correct | 163 ms | 75076 KB | Output is correct |
23 | Correct | 213 ms | 96096 KB | Output is correct |
24 | Correct | 118 ms | 65596 KB | Output is correct |
25 | Correct | 201 ms | 74688 KB | Output is correct |
26 | Correct | 250 ms | 72744 KB | Output is correct |
27 | Correct | 159 ms | 73408 KB | Output is correct |
28 | Correct | 180 ms | 73640 KB | Output is correct |
29 | Correct | 186 ms | 75068 KB | Output is correct |
30 | Correct | 175 ms | 73916 KB | Output is correct |
31 | Correct | 13 ms | 37464 KB | Output is correct |
32 | Correct | 280 ms | 94800 KB | Output is correct |
33 | Correct | 261 ms | 94120 KB | Output is correct |
34 | Correct | 245 ms | 75052 KB | Output is correct |
35 | Correct | 157 ms | 73464 KB | Output is correct |
36 | Correct | 264 ms | 93596 KB | Output is correct |
37 | Correct | 229 ms | 74944 KB | Output is correct |
38 | Correct | 247 ms | 74912 KB | Output is correct |
39 | Correct | 164 ms | 73972 KB | Output is correct |
40 | Correct | 147 ms | 69704 KB | Output is correct |
41 | Correct | 159 ms | 75712 KB | Output is correct |
42 | Correct | 14 ms | 37608 KB | Output is correct |
43 | Correct | 302 ms | 79984 KB | Output is correct |
44 | Correct | 291 ms | 83136 KB | Output is correct |
45 | Correct | 338 ms | 90408 KB | Output is correct |
46 | Correct | 386 ms | 100048 KB | Output is correct |
47 | Correct | 337 ms | 85692 KB | Output is correct |
48 | Correct | 237 ms | 75308 KB | Output is correct |
49 | Correct | 145 ms | 73404 KB | Output is correct |
50 | Correct | 164 ms | 57588 KB | Output is correct |
51 | Correct | 414 ms | 104192 KB | Output is correct |
52 | Correct | 166 ms | 75152 KB | Output is correct |
53 | Correct | 13 ms | 35676 KB | Output is correct |
54 | Correct | 13 ms | 35700 KB | Output is correct |
55 | Correct | 13 ms | 35676 KB | Output is correct |
56 | Correct | 19 ms | 35932 KB | Output is correct |
57 | Correct | 14 ms | 35928 KB | Output is correct |
58 | Correct | 18 ms | 35944 KB | Output is correct |
59 | Correct | 16 ms | 36188 KB | Output is correct |
60 | Correct | 14 ms | 35960 KB | Output is correct |
61 | Correct | 18 ms | 35928 KB | Output is correct |
62 | Correct | 19 ms | 35960 KB | Output is correct |
63 | Correct | 18 ms | 36188 KB | Output is correct |
64 | Correct | 15 ms | 36196 KB | Output is correct |
65 | Correct | 15 ms | 35932 KB | Output is correct |
66 | Correct | 15 ms | 35880 KB | Output is correct |
67 | Correct | 188 ms | 73916 KB | Output is correct |
68 | Correct | 165 ms | 73404 KB | Output is correct |
69 | Correct | 229 ms | 84204 KB | Output is correct |
70 | Correct | 308 ms | 87208 KB | Output is correct |
71 | Correct | 281 ms | 86460 KB | Output is correct |
72 | Correct | 206 ms | 74600 KB | Output is correct |
73 | Correct | 211 ms | 95680 KB | Output is correct |
74 | Correct | 107 ms | 65216 KB | Output is correct |
75 | Correct | 213 ms | 74468 KB | Output is correct |
76 | Correct | 218 ms | 72400 KB | Output is correct |
77 | Correct | 191 ms | 73116 KB | Output is correct |
78 | Correct | 179 ms | 75076 KB | Output is correct |
79 | Correct | 214 ms | 75056 KB | Output is correct |
80 | Correct | 173 ms | 74036 KB | Output is correct |
81 | Correct | 304 ms | 93964 KB | Output is correct |
82 | Correct | 301 ms | 94148 KB | Output is correct |
83 | Correct | 205 ms | 74972 KB | Output is correct |
84 | Correct | 145 ms | 73540 KB | Output is correct |
85 | Correct | 296 ms | 93628 KB | Output is correct |
86 | Correct | 193 ms | 74896 KB | Output is correct |
87 | Correct | 192 ms | 75064 KB | Output is correct |
88 | Correct | 190 ms | 69568 KB | Output is correct |
89 | Correct | 192 ms | 75708 KB | Output is correct |
90 | Correct | 280 ms | 79812 KB | Output is correct |
91 | Correct | 282 ms | 82988 KB | Output is correct |
92 | Correct | 349 ms | 90364 KB | Output is correct |
93 | Correct | 408 ms | 100432 KB | Output is correct |
94 | Correct | 317 ms | 86056 KB | Output is correct |
95 | Correct | 229 ms | 77244 KB | Output is correct |
96 | Correct | 159 ms | 73932 KB | Output is correct |
97 | Correct | 144 ms | 58564 KB | Output is correct |
98 | Correct | 415 ms | 104636 KB | Output is correct |
99 | Correct | 184 ms | 75436 KB | Output is correct |
100 | Correct | 39 ms | 41904 KB | Output is correct |
101 | Correct | 365 ms | 84392 KB | Output is correct |
102 | Correct | 242 ms | 73148 KB | Output is correct |
103 | Correct | 314 ms | 68684 KB | Output is correct |
104 | Correct | 295 ms | 76480 KB | Output is correct |