Submission #601497

# Submission time Handle Problem Language Result Execution time Memory
601497 2022-07-22T06:05:54 Z 조영욱(#8474) Stranded Far From Home (BOI22_island) C++17
100 / 100
260 ms 20984 KB
#include <bits/stdc++.h>
using namespace std;

int n,m;
vector<int> adj[200001];
typedef pair<int,int> P;
P arr[200001];
bool chk[200000];
int save[200000];
int need[200001];
long long p[200000];
long long total[200000];
bool ret[200000];

int find(int a) {
    return p[a]<0?a:p[a]=find(p[a]);
}

void merge(int a,int b) {
    a=find(a);
    b=find(b);
    if (a!=b) {
        p[a]+=p[b];
        p[b]=a;
    }
}

int main() {
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++) {
        scanf("%d",&arr[i].first);
        save[i]=arr[i].first;
        arr[i].second=i;
    }
    sort(arr,arr+n);
    for(int i=0;i<m;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++) {
        p[i]=-save[i];
    }
    for(int i=0;i<n;i++) {
        int now=arr[i].second;
        for(int j=0;j<adj[now].size();j++) {
            int nt=adj[now][j];
            if (!chk[nt]) {
                continue;
            }
            if (find(now)==find(nt)) {
                continue;
            }
            need[find(nt)]=now;
            merge(now,nt);
        }
        chk[now]=true;
        total[now]=-p[find(now)];
    }
    for(int i=n-1;i>=0;i--) {
        int now=arr[i].second;
        if (i==n-1) {
            ret[now]=true;
            continue;
        }
        if (ret[need[now]]&&save[need[now]]<=total[now]) {
            ret[now]=true;
        }
    }
    for(int i=0;i<n;i++) {
        printf("%d",ret[i]);
    }
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
island.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
island.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d",&arr[i].first);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
island.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5096 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 6 ms 5076 KB Output is correct
11 Correct 5 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5156 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 145 ms 18020 KB Output is correct
4 Correct 151 ms 19224 KB Output is correct
5 Correct 181 ms 17744 KB Output is correct
6 Correct 162 ms 18120 KB Output is correct
7 Correct 152 ms 18068 KB Output is correct
8 Correct 201 ms 18092 KB Output is correct
9 Correct 162 ms 18004 KB Output is correct
10 Correct 126 ms 18664 KB Output is correct
11 Correct 140 ms 18832 KB Output is correct
12 Correct 194 ms 17936 KB Output is correct
13 Correct 153 ms 20908 KB Output is correct
14 Correct 148 ms 20756 KB Output is correct
15 Correct 164 ms 18024 KB Output is correct
16 Correct 104 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 172 ms 17996 KB Output is correct
3 Correct 175 ms 18036 KB Output is correct
4 Correct 160 ms 17984 KB Output is correct
5 Correct 174 ms 18868 KB Output is correct
6 Correct 178 ms 18060 KB Output is correct
7 Correct 207 ms 18076 KB Output is correct
8 Correct 193 ms 18156 KB Output is correct
9 Correct 110 ms 17852 KB Output is correct
10 Correct 151 ms 19596 KB Output is correct
11 Correct 176 ms 18476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 186 ms 18012 KB Output is correct
3 Correct 183 ms 18088 KB Output is correct
4 Correct 204 ms 18132 KB Output is correct
5 Correct 206 ms 18104 KB Output is correct
6 Correct 199 ms 17484 KB Output is correct
7 Correct 168 ms 18876 KB Output is correct
8 Correct 110 ms 19504 KB Output is correct
9 Correct 140 ms 12460 KB Output is correct
10 Correct 168 ms 17968 KB Output is correct
11 Correct 156 ms 18476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5096 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 6 ms 5076 KB Output is correct
11 Correct 5 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5156 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 145 ms 18020 KB Output is correct
18 Correct 151 ms 19224 KB Output is correct
19 Correct 181 ms 17744 KB Output is correct
20 Correct 162 ms 18120 KB Output is correct
21 Correct 152 ms 18068 KB Output is correct
22 Correct 201 ms 18092 KB Output is correct
23 Correct 162 ms 18004 KB Output is correct
24 Correct 126 ms 18664 KB Output is correct
25 Correct 140 ms 18832 KB Output is correct
26 Correct 194 ms 17936 KB Output is correct
27 Correct 153 ms 20908 KB Output is correct
28 Correct 148 ms 20756 KB Output is correct
29 Correct 164 ms 18024 KB Output is correct
30 Correct 104 ms 17912 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 172 ms 17996 KB Output is correct
33 Correct 175 ms 18036 KB Output is correct
34 Correct 160 ms 17984 KB Output is correct
35 Correct 174 ms 18868 KB Output is correct
36 Correct 178 ms 18060 KB Output is correct
37 Correct 207 ms 18076 KB Output is correct
38 Correct 193 ms 18156 KB Output is correct
39 Correct 110 ms 17852 KB Output is correct
40 Correct 151 ms 19596 KB Output is correct
41 Correct 176 ms 18476 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 186 ms 18012 KB Output is correct
44 Correct 183 ms 18088 KB Output is correct
45 Correct 204 ms 18132 KB Output is correct
46 Correct 206 ms 18104 KB Output is correct
47 Correct 199 ms 17484 KB Output is correct
48 Correct 168 ms 18876 KB Output is correct
49 Correct 110 ms 19504 KB Output is correct
50 Correct 140 ms 12460 KB Output is correct
51 Correct 168 ms 17968 KB Output is correct
52 Correct 156 ms 18476 KB Output is correct
53 Correct 3 ms 5040 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4920 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5076 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 5 ms 5076 KB Output is correct
61 Correct 5 ms 5076 KB Output is correct
62 Correct 6 ms 5076 KB Output is correct
63 Correct 4 ms 5076 KB Output is correct
64 Correct 5 ms 5076 KB Output is correct
65 Correct 5 ms 5096 KB Output is correct
66 Correct 4 ms 5076 KB Output is correct
67 Correct 186 ms 18020 KB Output is correct
68 Correct 146 ms 19244 KB Output is correct
69 Correct 163 ms 17640 KB Output is correct
70 Correct 211 ms 18116 KB Output is correct
71 Correct 159 ms 18112 KB Output is correct
72 Correct 193 ms 18104 KB Output is correct
73 Correct 183 ms 18124 KB Output is correct
74 Correct 118 ms 18668 KB Output is correct
75 Correct 143 ms 18852 KB Output is correct
76 Correct 160 ms 18080 KB Output is correct
77 Correct 160 ms 20984 KB Output is correct
78 Correct 153 ms 20704 KB Output is correct
79 Correct 147 ms 17984 KB Output is correct
80 Correct 122 ms 17880 KB Output is correct
81 Correct 196 ms 18056 KB Output is correct
82 Correct 199 ms 18152 KB Output is correct
83 Correct 174 ms 17972 KB Output is correct
84 Correct 173 ms 18872 KB Output is correct
85 Correct 204 ms 18080 KB Output is correct
86 Correct 159 ms 18088 KB Output is correct
87 Correct 156 ms 18084 KB Output is correct
88 Correct 176 ms 19596 KB Output is correct
89 Correct 158 ms 18376 KB Output is correct
90 Correct 187 ms 18096 KB Output is correct
91 Correct 231 ms 18024 KB Output is correct
92 Correct 192 ms 18080 KB Output is correct
93 Correct 195 ms 18000 KB Output is correct
94 Correct 194 ms 17448 KB Output is correct
95 Correct 133 ms 18876 KB Output is correct
96 Correct 112 ms 19496 KB Output is correct
97 Correct 136 ms 12536 KB Output is correct
98 Correct 177 ms 18060 KB Output is correct
99 Correct 175 ms 18368 KB Output is correct
100 Correct 57 ms 7436 KB Output is correct
101 Correct 205 ms 18108 KB Output is correct
102 Correct 153 ms 15300 KB Output is correct
103 Correct 182 ms 15988 KB Output is correct
104 Correct 260 ms 17848 KB Output is correct