Submission #837213

# Submission time Handle Problem Language Result Execution time Memory
837213 2023-08-25T08:12:00 Z Hanksburger Stranded Far From Home (BOI22_island) C++17
100 / 100
199 ms 46636 KB
#include <bits/stdc++.h>
using namespace std;
long long s[200005], par[200005], sz[200005], ok[200005];
vector<long long> adj[200005], child[200005];
pair<long long, long long> a[200005];
long long findPar(long long u)
{
    return (par[u]==u)?u:(par[u]=findPar(par[u]));
}
void dfs(long long u)
{
    sz[u]=s[u];
    for (long long v:child[u])
    {
        dfs(v);
        sz[u]+=sz[v];
    }
}
void dfs2(long long u, long long p)
{
    if (sz[u]<s[p])
        return;
    ok[u]=1;
    for (long long v:child[u])
        dfs2(v, u);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, m;
    cin >> n >> m;
    for (long long i=1; i<=n; i++)
    {
        cin >> s[i];
        a[i]={s[i], i};
    }
    sort(a+1, a+n+1);
    for (long long i=1; i<=m; i++)
    {
        long long u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (long long i=1; i<=n; i++)
        par[i]=i;
    for (long long i=1; i<=n; i++)
    {
        set<long long> ss;
        long long u=a[i].second;
        for (long long v:adj[u])
            if ((s[v]<s[u] || (s[v]==s[u] && v<u)) && ss.find(findPar(v))==ss.end())
                ss.insert(par[v]);
        for (long long v:ss)
        {
            par[v]=u;
            child[u].push_back(v);
        }
    }
    dfs(a[n].second);
    dfs2(a[n].second, 0);
    for (long long i=1; i<=n; i++)
        cout << ok[i];
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9912 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9928 KB Output is correct
7 Correct 7 ms 9944 KB Output is correct
8 Correct 6 ms 9940 KB Output is correct
9 Correct 6 ms 10068 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 6 ms 9940 KB Output is correct
12 Correct 5 ms 9940 KB Output is correct
13 Correct 5 ms 9940 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 124 ms 38976 KB Output is correct
4 Correct 129 ms 42700 KB Output is correct
5 Correct 163 ms 34272 KB Output is correct
6 Correct 149 ms 34868 KB Output is correct
7 Correct 149 ms 34892 KB Output is correct
8 Correct 158 ms 46636 KB Output is correct
9 Correct 133 ms 33764 KB Output is correct
10 Correct 183 ms 40252 KB Output is correct
11 Correct 123 ms 46152 KB Output is correct
12 Correct 148 ms 34736 KB Output is correct
13 Correct 103 ms 42568 KB Output is correct
14 Correct 118 ms 41936 KB Output is correct
15 Correct 133 ms 45772 KB Output is correct
16 Correct 91 ms 44620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 180 ms 34172 KB Output is correct
3 Correct 155 ms 34060 KB Output is correct
4 Correct 127 ms 45644 KB Output is correct
5 Correct 106 ms 39492 KB Output is correct
6 Correct 154 ms 34096 KB Output is correct
7 Correct 140 ms 45648 KB Output is correct
8 Correct 141 ms 45648 KB Output is correct
9 Correct 93 ms 44636 KB Output is correct
10 Correct 114 ms 37152 KB Output is correct
11 Correct 131 ms 32972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 193 ms 35648 KB Output is correct
3 Correct 178 ms 35176 KB Output is correct
4 Correct 179 ms 35148 KB Output is correct
5 Correct 176 ms 35272 KB Output is correct
6 Correct 157 ms 35348 KB Output is correct
7 Correct 130 ms 42680 KB Output is correct
8 Correct 89 ms 45260 KB Output is correct
9 Correct 99 ms 25688 KB Output is correct
10 Correct 137 ms 32128 KB Output is correct
11 Correct 141 ms 32992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9912 KB Output is correct
5 Correct 6 ms 9940 KB Output is correct
6 Correct 6 ms 9928 KB Output is correct
7 Correct 7 ms 9944 KB Output is correct
8 Correct 6 ms 9940 KB Output is correct
9 Correct 6 ms 10068 KB Output is correct
10 Correct 6 ms 9940 KB Output is correct
11 Correct 6 ms 9940 KB Output is correct
12 Correct 5 ms 9940 KB Output is correct
13 Correct 5 ms 9940 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
15 Correct 4 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 124 ms 38976 KB Output is correct
18 Correct 129 ms 42700 KB Output is correct
19 Correct 163 ms 34272 KB Output is correct
20 Correct 149 ms 34868 KB Output is correct
21 Correct 149 ms 34892 KB Output is correct
22 Correct 158 ms 46636 KB Output is correct
23 Correct 133 ms 33764 KB Output is correct
24 Correct 183 ms 40252 KB Output is correct
25 Correct 123 ms 46152 KB Output is correct
26 Correct 148 ms 34736 KB Output is correct
27 Correct 103 ms 42568 KB Output is correct
28 Correct 118 ms 41936 KB Output is correct
29 Correct 133 ms 45772 KB Output is correct
30 Correct 91 ms 44620 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 180 ms 34172 KB Output is correct
33 Correct 155 ms 34060 KB Output is correct
34 Correct 127 ms 45644 KB Output is correct
35 Correct 106 ms 39492 KB Output is correct
36 Correct 154 ms 34096 KB Output is correct
37 Correct 140 ms 45648 KB Output is correct
38 Correct 141 ms 45648 KB Output is correct
39 Correct 93 ms 44636 KB Output is correct
40 Correct 114 ms 37152 KB Output is correct
41 Correct 131 ms 32972 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 193 ms 35648 KB Output is correct
44 Correct 178 ms 35176 KB Output is correct
45 Correct 179 ms 35148 KB Output is correct
46 Correct 176 ms 35272 KB Output is correct
47 Correct 157 ms 35348 KB Output is correct
48 Correct 130 ms 42680 KB Output is correct
49 Correct 89 ms 45260 KB Output is correct
50 Correct 99 ms 25688 KB Output is correct
51 Correct 137 ms 32128 KB Output is correct
52 Correct 141 ms 32992 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 6 ms 9684 KB Output is correct
56 Correct 7 ms 9940 KB Output is correct
57 Correct 6 ms 10000 KB Output is correct
58 Correct 6 ms 9940 KB Output is correct
59 Correct 5 ms 9940 KB Output is correct
60 Correct 5 ms 9940 KB Output is correct
61 Correct 7 ms 10068 KB Output is correct
62 Correct 8 ms 9940 KB Output is correct
63 Correct 7 ms 9940 KB Output is correct
64 Correct 5 ms 9940 KB Output is correct
65 Correct 6 ms 10088 KB Output is correct
66 Correct 5 ms 9940 KB Output is correct
67 Correct 127 ms 39048 KB Output is correct
68 Correct 113 ms 42668 KB Output is correct
69 Correct 135 ms 34056 KB Output is correct
70 Correct 144 ms 34904 KB Output is correct
71 Correct 158 ms 34844 KB Output is correct
72 Correct 167 ms 46572 KB Output is correct
73 Correct 112 ms 33788 KB Output is correct
74 Correct 196 ms 40168 KB Output is correct
75 Correct 120 ms 46196 KB Output is correct
76 Correct 150 ms 34748 KB Output is correct
77 Correct 110 ms 42552 KB Output is correct
78 Correct 110 ms 42060 KB Output is correct
79 Correct 110 ms 45656 KB Output is correct
80 Correct 88 ms 44540 KB Output is correct
81 Correct 172 ms 34000 KB Output is correct
82 Correct 184 ms 34296 KB Output is correct
83 Correct 128 ms 45600 KB Output is correct
84 Correct 101 ms 39500 KB Output is correct
85 Correct 169 ms 34116 KB Output is correct
86 Correct 126 ms 45644 KB Output is correct
87 Correct 125 ms 45644 KB Output is correct
88 Correct 107 ms 37068 KB Output is correct
89 Correct 120 ms 32972 KB Output is correct
90 Correct 178 ms 35776 KB Output is correct
91 Correct 179 ms 35164 KB Output is correct
92 Correct 199 ms 35184 KB Output is correct
93 Correct 165 ms 35264 KB Output is correct
94 Correct 143 ms 35336 KB Output is correct
95 Correct 125 ms 42780 KB Output is correct
96 Correct 85 ms 45260 KB Output is correct
97 Correct 107 ms 25732 KB Output is correct
98 Correct 139 ms 32100 KB Output is correct
99 Correct 136 ms 33068 KB Output is correct
100 Correct 36 ms 16456 KB Output is correct
101 Correct 188 ms 35148 KB Output is correct
102 Correct 139 ms 33656 KB Output is correct
103 Correct 164 ms 34444 KB Output is correct
104 Correct 190 ms 35752 KB Output is correct