답안 #1078889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078889 2024-08-28T07:49:13 Z hcng Stranded Far From Home (BOI22_island) C++14
100 / 100
102 ms 29612 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
char *p1, *p2, buf[1<<20];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read() {int x=0;char c=gc();while(!isdigit(c))c=gc();while(isdigit(c))x=x*10+c-'0',c=gc();return x;}
#define pc(c) putchar(c)
void write(int x) {if(x>9)write(x/10);pc('0'+x%10);}

int n, m;
int a[200010], b[200010];
vector<int> G[200010];
int dsu[200010], tag[200010], sum[200010];
int ans[200010], vis[200010];

int find(int u) {
    int r = (u == dsu[u]? u : find(dsu[u]));
    tag[u] |= tag[dsu[u]];
    if (tag[u]) ans[u] = 0;
    dsu[u] = r;
    return r;
}

signed main() {
    n = read(), m = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        dsu[i] = b[i] = i;
    }
    for (int i = 1; i <= m; i++) {
        int u = read(), v = read();
        G[u].push_back(v);
        G[v].push_back(u);
    }
    sort(b + 1, b + 1 + n, [](int x, int y){return a[x]<a[y];});
    for (int i = 1; i <= n; i++) {
        int u = b[i];
        ans[u] = vis[u] = 1;
        sum[u] = a[u];
        for (int v : G[u]) {
            if (!vis[v]) continue;
            v = find(v);
            if (v == u) continue;
            if (sum[v] < a[u]) tag[v] = 1;
            dsu[v] = u;
            sum[u] += sum[v];
        }
    }
    for (int i = 1; i <= n; i++) {
        find(i);
    }
    for (int i = 1; i <= n; i++) {
        write(ans[i]);
    }
    pc('\n');
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6744 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 60 ms 28356 KB Output is correct
4 Correct 62 ms 27288 KB Output is correct
5 Correct 50 ms 27560 KB Output is correct
6 Correct 55 ms 28264 KB Output is correct
7 Correct 65 ms 28240 KB Output is correct
8 Correct 59 ms 28240 KB Output is correct
9 Correct 51 ms 29268 KB Output is correct
10 Correct 45 ms 28232 KB Output is correct
11 Correct 37 ms 28116 KB Output is correct
12 Correct 56 ms 26960 KB Output is correct
13 Correct 46 ms 25944 KB Output is correct
14 Correct 45 ms 26196 KB Output is correct
15 Correct 48 ms 27260 KB Output is correct
16 Correct 30 ms 26460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 79 ms 27184 KB Output is correct
3 Correct 74 ms 27216 KB Output is correct
4 Correct 45 ms 27216 KB Output is correct
5 Correct 51 ms 26060 KB Output is correct
6 Correct 70 ms 27216 KB Output is correct
7 Correct 62 ms 27196 KB Output is correct
8 Correct 61 ms 27196 KB Output is correct
9 Correct 32 ms 26472 KB Output is correct
10 Correct 50 ms 26704 KB Output is correct
11 Correct 53 ms 25940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 73 ms 28204 KB Output is correct
3 Correct 71 ms 28252 KB Output is correct
4 Correct 74 ms 28240 KB Output is correct
5 Correct 64 ms 28320 KB Output is correct
6 Correct 66 ms 27400 KB Output is correct
7 Correct 38 ms 29612 KB Output is correct
8 Correct 40 ms 27988 KB Output is correct
9 Correct 53 ms 20456 KB Output is correct
10 Correct 61 ms 26960 KB Output is correct
11 Correct 52 ms 25916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6744 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 60 ms 28356 KB Output is correct
18 Correct 62 ms 27288 KB Output is correct
19 Correct 50 ms 27560 KB Output is correct
20 Correct 55 ms 28264 KB Output is correct
21 Correct 65 ms 28240 KB Output is correct
22 Correct 59 ms 28240 KB Output is correct
23 Correct 51 ms 29268 KB Output is correct
24 Correct 45 ms 28232 KB Output is correct
25 Correct 37 ms 28116 KB Output is correct
26 Correct 56 ms 26960 KB Output is correct
27 Correct 46 ms 25944 KB Output is correct
28 Correct 45 ms 26196 KB Output is correct
29 Correct 48 ms 27260 KB Output is correct
30 Correct 30 ms 26460 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 79 ms 27184 KB Output is correct
33 Correct 74 ms 27216 KB Output is correct
34 Correct 45 ms 27216 KB Output is correct
35 Correct 51 ms 26060 KB Output is correct
36 Correct 70 ms 27216 KB Output is correct
37 Correct 62 ms 27196 KB Output is correct
38 Correct 61 ms 27196 KB Output is correct
39 Correct 32 ms 26472 KB Output is correct
40 Correct 50 ms 26704 KB Output is correct
41 Correct 53 ms 25940 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
43 Correct 73 ms 28204 KB Output is correct
44 Correct 71 ms 28252 KB Output is correct
45 Correct 74 ms 28240 KB Output is correct
46 Correct 64 ms 28320 KB Output is correct
47 Correct 66 ms 27400 KB Output is correct
48 Correct 38 ms 29612 KB Output is correct
49 Correct 40 ms 27988 KB Output is correct
50 Correct 53 ms 20456 KB Output is correct
51 Correct 61 ms 26960 KB Output is correct
52 Correct 52 ms 25916 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 3 ms 6680 KB Output is correct
57 Correct 3 ms 6864 KB Output is correct
58 Correct 3 ms 6748 KB Output is correct
59 Correct 3 ms 6748 KB Output is correct
60 Correct 3 ms 6748 KB Output is correct
61 Correct 3 ms 6748 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 3 ms 6744 KB Output is correct
64 Correct 3 ms 6748 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 3 ms 6744 KB Output is correct
67 Correct 52 ms 28396 KB Output is correct
68 Correct 62 ms 27296 KB Output is correct
69 Correct 64 ms 27472 KB Output is correct
70 Correct 57 ms 28244 KB Output is correct
71 Correct 71 ms 28240 KB Output is correct
72 Correct 68 ms 28240 KB Output is correct
73 Correct 50 ms 29264 KB Output is correct
74 Correct 39 ms 28100 KB Output is correct
75 Correct 40 ms 28092 KB Output is correct
76 Correct 65 ms 26960 KB Output is correct
77 Correct 52 ms 25936 KB Output is correct
78 Correct 47 ms 26352 KB Output is correct
79 Correct 57 ms 27220 KB Output is correct
80 Correct 32 ms 26448 KB Output is correct
81 Correct 77 ms 27216 KB Output is correct
82 Correct 88 ms 27204 KB Output is correct
83 Correct 69 ms 27372 KB Output is correct
84 Correct 68 ms 26040 KB Output is correct
85 Correct 98 ms 27216 KB Output is correct
86 Correct 88 ms 27160 KB Output is correct
87 Correct 60 ms 27216 KB Output is correct
88 Correct 69 ms 26448 KB Output is correct
89 Correct 77 ms 25936 KB Output is correct
90 Correct 80 ms 28348 KB Output is correct
91 Correct 102 ms 28208 KB Output is correct
92 Correct 77 ms 28240 KB Output is correct
93 Correct 71 ms 28244 KB Output is correct
94 Correct 71 ms 27312 KB Output is correct
95 Correct 42 ms 29384 KB Output is correct
96 Correct 33 ms 27732 KB Output is correct
97 Correct 49 ms 20564 KB Output is correct
98 Correct 59 ms 26940 KB Output is correct
99 Correct 54 ms 25936 KB Output is correct
100 Correct 16 ms 14124 KB Output is correct
101 Correct 80 ms 28240 KB Output is correct
102 Correct 69 ms 25308 KB Output is correct
103 Correct 91 ms 25984 KB Output is correct
104 Correct 95 ms 27984 KB Output is correct