Submission #605576

# Submission time Handle Problem Language Result Execution time Memory
605576 2022-07-25T18:57:35 Z duality Stranded Far From Home (BOI22_island) C++17
100 / 100
235 ms 36504 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int s[200000];
vi adjList[200000];
vi S[200000];
int order[200000],parent[200000];
int find(int n) {
    if (parent[n] != n) parent[n] = find(parent[n]);
    return parent[n];
}
int seen[200000],ans[200000];
LLI ss[200000];
int main() {
    int i;
    int N,M;
    int u,v;
    scanf("%d %d",&N,&M);
    for (i = 0; i < N; i++) scanf("%d",&s[i]);
    for (i = 0; i < M; i++) {
        scanf("%d %d",&u,&v);
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
    }

    for (i = 0; i < N; i++) parent[i] = order[i] = i,S[i].pb(i),ss[i] = s[i];
    sort(order,order+N,[&](int a,int b) { return s[a] < s[b]; });
    for (i = 0; i < N; i++) {
        int u = order[i];
        seen[u] = 1;
        for (int v: adjList[u]) {
            if (seen[v]) {
                if (find(u) != find(v)) {
                    int uu = find(u),vv = find(v);
                    if (ss[vv] < s[u]) S[vv].clear();
                    if (S[uu].size() > S[vv].size()) swap(uu,vv);
                    for (int x: S[uu]) S[vv].pb(x);
                    S[uu].clear(),parent[uu] = vv,ss[vv] += ss[uu];
                }
            }
        }
    }
    for (int x: S[find(0)]) ans[x] = 1;
    for (i = 0; i < N; i++) printf("%d",ans[i]);
    printf("\n");

    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
island.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     for (i = 0; i < N; i++) scanf("%d",&s[i]);
      |                             ~~~~~^~~~~~~~~~~~
island.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9976 KB Output is correct
13 Correct 6 ms 9848 KB Output is correct
14 Correct 6 ms 9840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 167 ms 30740 KB Output is correct
4 Correct 183 ms 32708 KB Output is correct
5 Correct 180 ms 31620 KB Output is correct
6 Correct 191 ms 32724 KB Output is correct
7 Correct 181 ms 33340 KB Output is correct
8 Correct 204 ms 32672 KB Output is correct
9 Correct 166 ms 33948 KB Output is correct
10 Correct 128 ms 30908 KB Output is correct
11 Correct 140 ms 32356 KB Output is correct
12 Correct 197 ms 30972 KB Output is correct
13 Correct 161 ms 32844 KB Output is correct
14 Correct 169 ms 33620 KB Output is correct
15 Correct 164 ms 32384 KB Output is correct
16 Correct 118 ms 31188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 222 ms 35000 KB Output is correct
3 Correct 235 ms 34120 KB Output is correct
4 Correct 169 ms 36504 KB Output is correct
5 Correct 168 ms 34368 KB Output is correct
6 Correct 218 ms 34852 KB Output is correct
7 Correct 181 ms 32300 KB Output is correct
8 Correct 181 ms 32084 KB Output is correct
9 Correct 111 ms 31176 KB Output is correct
10 Correct 171 ms 31664 KB Output is correct
11 Correct 188 ms 33304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9700 KB Output is correct
2 Correct 213 ms 32548 KB Output is correct
3 Correct 217 ms 34140 KB Output is correct
4 Correct 207 ms 32288 KB Output is correct
5 Correct 203 ms 36112 KB Output is correct
6 Correct 193 ms 32952 KB Output is correct
7 Correct 144 ms 33768 KB Output is correct
8 Correct 121 ms 33440 KB Output is correct
9 Correct 119 ms 22544 KB Output is correct
10 Correct 206 ms 34064 KB Output is correct
11 Correct 183 ms 32604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9976 KB Output is correct
13 Correct 6 ms 9848 KB Output is correct
14 Correct 6 ms 9840 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 167 ms 30740 KB Output is correct
18 Correct 183 ms 32708 KB Output is correct
19 Correct 180 ms 31620 KB Output is correct
20 Correct 191 ms 32724 KB Output is correct
21 Correct 181 ms 33340 KB Output is correct
22 Correct 204 ms 32672 KB Output is correct
23 Correct 166 ms 33948 KB Output is correct
24 Correct 128 ms 30908 KB Output is correct
25 Correct 140 ms 32356 KB Output is correct
26 Correct 197 ms 30972 KB Output is correct
27 Correct 161 ms 32844 KB Output is correct
28 Correct 169 ms 33620 KB Output is correct
29 Correct 164 ms 32384 KB Output is correct
30 Correct 118 ms 31188 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 222 ms 35000 KB Output is correct
33 Correct 235 ms 34120 KB Output is correct
34 Correct 169 ms 36504 KB Output is correct
35 Correct 168 ms 34368 KB Output is correct
36 Correct 218 ms 34852 KB Output is correct
37 Correct 181 ms 32300 KB Output is correct
38 Correct 181 ms 32084 KB Output is correct
39 Correct 111 ms 31176 KB Output is correct
40 Correct 171 ms 31664 KB Output is correct
41 Correct 188 ms 33304 KB Output is correct
42 Correct 6 ms 9700 KB Output is correct
43 Correct 213 ms 32548 KB Output is correct
44 Correct 217 ms 34140 KB Output is correct
45 Correct 207 ms 32288 KB Output is correct
46 Correct 203 ms 36112 KB Output is correct
47 Correct 193 ms 32952 KB Output is correct
48 Correct 144 ms 33768 KB Output is correct
49 Correct 121 ms 33440 KB Output is correct
50 Correct 119 ms 22544 KB Output is correct
51 Correct 206 ms 34064 KB Output is correct
52 Correct 183 ms 32604 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9696 KB Output is correct
55 Correct 5 ms 9672 KB Output is correct
56 Correct 6 ms 9880 KB Output is correct
57 Correct 7 ms 9972 KB Output is correct
58 Correct 7 ms 9840 KB Output is correct
59 Correct 6 ms 9840 KB Output is correct
60 Correct 6 ms 9844 KB Output is correct
61 Correct 6 ms 9940 KB Output is correct
62 Correct 6 ms 9940 KB Output is correct
63 Correct 6 ms 9940 KB Output is correct
64 Correct 7 ms 9940 KB Output is correct
65 Correct 6 ms 9940 KB Output is correct
66 Correct 6 ms 9940 KB Output is correct
67 Correct 174 ms 32728 KB Output is correct
68 Correct 166 ms 33980 KB Output is correct
69 Correct 178 ms 34240 KB Output is correct
70 Correct 181 ms 34076 KB Output is correct
71 Correct 179 ms 32160 KB Output is correct
72 Correct 194 ms 32960 KB Output is correct
73 Correct 168 ms 34524 KB Output is correct
74 Correct 127 ms 29544 KB Output is correct
75 Correct 138 ms 31640 KB Output is correct
76 Correct 191 ms 30720 KB Output is correct
77 Correct 161 ms 33332 KB Output is correct
78 Correct 162 ms 32960 KB Output is correct
79 Correct 166 ms 32392 KB Output is correct
80 Correct 109 ms 32324 KB Output is correct
81 Correct 211 ms 34480 KB Output is correct
82 Correct 229 ms 34500 KB Output is correct
83 Correct 165 ms 32436 KB Output is correct
84 Correct 170 ms 34008 KB Output is correct
85 Correct 222 ms 35948 KB Output is correct
86 Correct 178 ms 33096 KB Output is correct
87 Correct 176 ms 33052 KB Output is correct
88 Correct 169 ms 30812 KB Output is correct
89 Correct 184 ms 30748 KB Output is correct
90 Correct 212 ms 31784 KB Output is correct
91 Correct 204 ms 34124 KB Output is correct
92 Correct 210 ms 35144 KB Output is correct
93 Correct 203 ms 35376 KB Output is correct
94 Correct 187 ms 32540 KB Output is correct
95 Correct 139 ms 33088 KB Output is correct
96 Correct 118 ms 32900 KB Output is correct
97 Correct 120 ms 22220 KB Output is correct
98 Correct 199 ms 34700 KB Output is correct
99 Correct 181 ms 33372 KB Output is correct
100 Correct 54 ms 13876 KB Output is correct
101 Correct 232 ms 34448 KB Output is correct
102 Correct 195 ms 27940 KB Output is correct
103 Correct 178 ms 25764 KB Output is correct
104 Correct 218 ms 29220 KB Output is correct