Submission #604064

# Submission time Handle Problem Language Result Execution time Memory
604064 2022-07-24T16:26:12 Z Ahmadsm2005 Stranded Far From Home (BOI22_island) C++17
100 / 100
512 ms 46988 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,M,V[200001],X,Y,VIS[200001];
int R[200001],DSU[200001],SUM[200001];
vector<int>edges[200001];
set<int>DSU2[200001];
int FIND(int X){
if(DSU[X] == X)return X;
return FIND(DSU[X]);
}
int32_t main()
{
    cin.tie(0),iostream::sync_with_stdio(0);
    cin>>N>>M;
    vector<pair<int,int>>FF;
    for(int i = 0; i < N; i += 1){
        cin>>V[i];
        FF.push_back({V[i],i});
    }
    for(int i = 0; i < N; i += 1)DSU2[i].insert(i),DSU[i] = i,SUM[i] = V[i],R[i] = 1;
    sort(FF.begin(),FF.end());
    for(int i = 0; i < M; i += 1){
        cin>>X>>Y;
        edges[X - 1].push_back(Y - 1),edges[Y - 1].push_back(X - 1);
    }
    for(int i = 0 ;i < N; i += 1){
        int IDX = FF[i].second, WE = FF[i].first;
        //cout<<"lol"<<endl;
        for(int l = 0; l < edges[IDX].size();l++){
            int F2 = FIND(IDX);
            if(V[edges[IDX][l]] > WE)continue;
            int F1 = FIND(edges[IDX][l]);
            if(F1 == F2)continue;
            int S = SUM[F1];
            //cout<<S<<' '<<WE<<endl;
            if(S < WE){
                for(auto itr = DSU2[F1].begin();itr!=DSU2[F1].end();itr++){
                    R[*itr] = 0;
                }
                DSU2[F1].clear();
            }
            if(DSU2[F1].size() < DSU2[F2].size())swap(F1,F2);
            SUM[F1] += SUM[F2];
            DSU[F2] = F1;
            SUM[F2] = 0;
            for(auto itr = DSU2[F2].begin(); itr != DSU2[F2].end();itr++)
            DSU2[F1].insert(*itr);
            DSU2[F2].clear();
        }
    }
    for(int i = 0; i < N; i += 1)cout<<R[i];
}

Compilation message

island.cpp: In function 'int32_t main()':
island.cpp:30:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int l = 0; l < edges[IDX].size();l++){
      |                        ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14444 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 10 ms 14612 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 8 ms 14588 KB Output is correct
9 Correct 9 ms 14676 KB Output is correct
10 Correct 8 ms 14676 KB Output is correct
11 Correct 8 ms 14600 KB Output is correct
12 Correct 9 ms 14716 KB Output is correct
13 Correct 9 ms 14672 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14440 KB Output is correct
2 Correct 8 ms 14332 KB Output is correct
3 Correct 193 ms 40548 KB Output is correct
4 Correct 178 ms 41032 KB Output is correct
5 Correct 293 ms 40184 KB Output is correct
6 Correct 330 ms 40992 KB Output is correct
7 Correct 311 ms 41004 KB Output is correct
8 Correct 345 ms 41040 KB Output is correct
9 Correct 214 ms 42296 KB Output is correct
10 Correct 189 ms 41616 KB Output is correct
11 Correct 390 ms 41596 KB Output is correct
12 Correct 315 ms 41008 KB Output is correct
13 Correct 187 ms 39944 KB Output is correct
14 Correct 183 ms 40004 KB Output is correct
15 Correct 207 ms 40056 KB Output is correct
16 Correct 141 ms 39720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 319 ms 39500 KB Output is correct
3 Correct 327 ms 42172 KB Output is correct
4 Correct 243 ms 43876 KB Output is correct
5 Correct 181 ms 42304 KB Output is correct
6 Correct 374 ms 43012 KB Output is correct
7 Correct 222 ms 42968 KB Output is correct
8 Correct 200 ms 42916 KB Output is correct
9 Correct 150 ms 41800 KB Output is correct
10 Correct 170 ms 41400 KB Output is correct
11 Correct 193 ms 42448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 387 ms 40496 KB Output is correct
3 Correct 364 ms 44756 KB Output is correct
4 Correct 414 ms 42208 KB Output is correct
5 Correct 505 ms 46148 KB Output is correct
6 Correct 403 ms 43356 KB Output is correct
7 Correct 223 ms 45452 KB Output is correct
8 Correct 138 ms 44552 KB Output is correct
9 Correct 163 ms 31784 KB Output is correct
10 Correct 512 ms 46080 KB Output is correct
11 Correct 198 ms 41760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14444 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 10 ms 14612 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 8 ms 14588 KB Output is correct
9 Correct 9 ms 14676 KB Output is correct
10 Correct 8 ms 14676 KB Output is correct
11 Correct 8 ms 14600 KB Output is correct
12 Correct 9 ms 14716 KB Output is correct
13 Correct 9 ms 14672 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
15 Correct 8 ms 14440 KB Output is correct
16 Correct 8 ms 14332 KB Output is correct
17 Correct 193 ms 40548 KB Output is correct
18 Correct 178 ms 41032 KB Output is correct
19 Correct 293 ms 40184 KB Output is correct
20 Correct 330 ms 40992 KB Output is correct
21 Correct 311 ms 41004 KB Output is correct
22 Correct 345 ms 41040 KB Output is correct
23 Correct 214 ms 42296 KB Output is correct
24 Correct 189 ms 41616 KB Output is correct
25 Correct 390 ms 41596 KB Output is correct
26 Correct 315 ms 41008 KB Output is correct
27 Correct 187 ms 39944 KB Output is correct
28 Correct 183 ms 40004 KB Output is correct
29 Correct 207 ms 40056 KB Output is correct
30 Correct 141 ms 39720 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 319 ms 39500 KB Output is correct
33 Correct 327 ms 42172 KB Output is correct
34 Correct 243 ms 43876 KB Output is correct
35 Correct 181 ms 42304 KB Output is correct
36 Correct 374 ms 43012 KB Output is correct
37 Correct 222 ms 42968 KB Output is correct
38 Correct 200 ms 42916 KB Output is correct
39 Correct 150 ms 41800 KB Output is correct
40 Correct 170 ms 41400 KB Output is correct
41 Correct 193 ms 42448 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 387 ms 40496 KB Output is correct
44 Correct 364 ms 44756 KB Output is correct
45 Correct 414 ms 42208 KB Output is correct
46 Correct 505 ms 46148 KB Output is correct
47 Correct 403 ms 43356 KB Output is correct
48 Correct 223 ms 45452 KB Output is correct
49 Correct 138 ms 44552 KB Output is correct
50 Correct 163 ms 31784 KB Output is correct
51 Correct 512 ms 46080 KB Output is correct
52 Correct 198 ms 41760 KB Output is correct
53 Correct 7 ms 14368 KB Output is correct
54 Correct 7 ms 14420 KB Output is correct
55 Correct 7 ms 14420 KB Output is correct
56 Correct 8 ms 14664 KB Output is correct
57 Correct 9 ms 14684 KB Output is correct
58 Correct 8 ms 14676 KB Output is correct
59 Correct 8 ms 14692 KB Output is correct
60 Correct 9 ms 14548 KB Output is correct
61 Correct 9 ms 14652 KB Output is correct
62 Correct 9 ms 14692 KB Output is correct
63 Correct 9 ms 14684 KB Output is correct
64 Correct 10 ms 14676 KB Output is correct
65 Correct 8 ms 14676 KB Output is correct
66 Correct 10 ms 14732 KB Output is correct
67 Correct 205 ms 44860 KB Output is correct
68 Correct 174 ms 43452 KB Output is correct
69 Correct 291 ms 44064 KB Output is correct
70 Correct 357 ms 44016 KB Output is correct
71 Correct 329 ms 42172 KB Output is correct
72 Correct 289 ms 43700 KB Output is correct
73 Correct 271 ms 44896 KB Output is correct
74 Correct 186 ms 42920 KB Output is correct
75 Correct 374 ms 43300 KB Output is correct
76 Correct 266 ms 42484 KB Output is correct
77 Correct 193 ms 41460 KB Output is correct
78 Correct 193 ms 41288 KB Output is correct
79 Correct 191 ms 43232 KB Output is correct
80 Correct 145 ms 43076 KB Output is correct
81 Correct 336 ms 41900 KB Output is correct
82 Correct 352 ms 42704 KB Output is correct
83 Correct 225 ms 39760 KB Output is correct
84 Correct 188 ms 41876 KB Output is correct
85 Correct 329 ms 44088 KB Output is correct
86 Correct 233 ms 44012 KB Output is correct
87 Correct 226 ms 43900 KB Output is correct
88 Correct 187 ms 40600 KB Output is correct
89 Correct 200 ms 39776 KB Output is correct
90 Correct 384 ms 43112 KB Output is correct
91 Correct 358 ms 44836 KB Output is correct
92 Correct 468 ms 45076 KB Output is correct
93 Correct 456 ms 45300 KB Output is correct
94 Correct 411 ms 42884 KB Output is correct
95 Correct 227 ms 44724 KB Output is correct
96 Correct 150 ms 43980 KB Output is correct
97 Correct 172 ms 31560 KB Output is correct
98 Correct 463 ms 46988 KB Output is correct
99 Correct 185 ms 42424 KB Output is correct
100 Correct 63 ms 21020 KB Output is correct
101 Correct 420 ms 44956 KB Output is correct
102 Correct 329 ms 38924 KB Output is correct
103 Correct 326 ms 37300 KB Output is correct
104 Correct 344 ms 40636 KB Output is correct