Submission #696866

# Submission time Handle Problem Language Result Execution time Memory
696866 2023-02-07T13:24:23 Z Tien_Noob Stranded Far From Home (BOI22_island) C++17
100 / 100
215 ms 35460 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
int lab[N + 1];
vector<int> f[N + 1], adj[N + 1];
long long sum[N + 1];
int n, m, id[N + 1], s[N + 1];
bool res[N + 1];
int FindSet(int u)
{
    return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]);
}
void unite(int u, int v)
{
    u = FindSet(u);
    v = FindSet(v);
    if (u == v)
    {
        return ;
    }
    if (lab[u] > lab[v])
    {
        swap(u, v);
    }
    lab[u] += lab[v];
    sum[u] += sum[v];
    lab[v] = u;
    move(f[v].begin(), f[v].end(), back_inserter(f[u]));
}
void read()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> s[i];
        sum[i] = s[i];
        lab[i] = -1;
        f[i] = {i};
        id[i] = i;
    }
    while(m--)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}
void solve()
{
    sort(id + 1, id + n + 1, [&](const int x, const int &y)
         {
             return s[x] < s[y];
         });
    for (int i = 1; i <= n; ++ i)
    {
        int u = id[i];
        for (int v : adj[u])
        {
            if (s[v] <= s[u])
            {
                if (sum[FindSet(v)] < s[u])
                {
                    f[FindSet(v)].clear();
                }
                unite(u, v);
            }
        }
    }
    int root = FindSet(id[n]);
    for (int u : f[root])
    {
        res[u] = true;
    }
    for (int u = 1; u <= n; ++ u)
    {
        cout << res[u];
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 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 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 5 ms 9820 KB Output is correct
7 Correct 6 ms 9868 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 7 ms 9960 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 7 ms 9868 KB Output is correct
14 Correct 6 ms 9940 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 164 ms 31836 KB Output is correct
4 Correct 149 ms 33276 KB Output is correct
5 Correct 161 ms 32980 KB Output is correct
6 Correct 182 ms 33792 KB Output is correct
7 Correct 174 ms 33692 KB Output is correct
8 Correct 180 ms 33560 KB Output is correct
9 Correct 144 ms 34804 KB Output is correct
10 Correct 105 ms 30644 KB Output is correct
11 Correct 111 ms 31876 KB Output is correct
12 Correct 163 ms 31104 KB Output is correct
13 Correct 138 ms 33720 KB Output is correct
14 Correct 164 ms 33384 KB Output is correct
15 Correct 135 ms 31808 KB Output is correct
16 Correct 91 ms 31024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 195 ms 34604 KB Output is correct
3 Correct 193 ms 34544 KB Output is correct
4 Correct 155 ms 35460 KB Output is correct
5 Correct 142 ms 33656 KB Output is correct
6 Correct 209 ms 34704 KB Output is correct
7 Correct 151 ms 31928 KB Output is correct
8 Correct 153 ms 31808 KB Output is correct
9 Correct 88 ms 30928 KB Output is correct
10 Correct 152 ms 32260 KB Output is correct
11 Correct 171 ms 32560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 215 ms 32424 KB Output is correct
3 Correct 207 ms 32892 KB Output is correct
4 Correct 196 ms 33688 KB Output is correct
5 Correct 189 ms 34844 KB Output is correct
6 Correct 187 ms 32360 KB Output is correct
7 Correct 119 ms 32828 KB Output is correct
8 Correct 102 ms 31812 KB Output is correct
9 Correct 100 ms 22280 KB Output is correct
10 Correct 196 ms 33676 KB Output is correct
11 Correct 158 ms 32780 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 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 5 ms 9820 KB Output is correct
7 Correct 6 ms 9868 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 7 ms 9960 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 7 ms 9868 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 164 ms 31836 KB Output is correct
18 Correct 149 ms 33276 KB Output is correct
19 Correct 161 ms 32980 KB Output is correct
20 Correct 182 ms 33792 KB Output is correct
21 Correct 174 ms 33692 KB Output is correct
22 Correct 180 ms 33560 KB Output is correct
23 Correct 144 ms 34804 KB Output is correct
24 Correct 105 ms 30644 KB Output is correct
25 Correct 111 ms 31876 KB Output is correct
26 Correct 163 ms 31104 KB Output is correct
27 Correct 138 ms 33720 KB Output is correct
28 Correct 164 ms 33384 KB Output is correct
29 Correct 135 ms 31808 KB Output is correct
30 Correct 91 ms 31024 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 195 ms 34604 KB Output is correct
33 Correct 193 ms 34544 KB Output is correct
34 Correct 155 ms 35460 KB Output is correct
35 Correct 142 ms 33656 KB Output is correct
36 Correct 209 ms 34704 KB Output is correct
37 Correct 151 ms 31928 KB Output is correct
38 Correct 153 ms 31808 KB Output is correct
39 Correct 88 ms 30928 KB Output is correct
40 Correct 152 ms 32260 KB Output is correct
41 Correct 171 ms 32560 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 215 ms 32424 KB Output is correct
44 Correct 207 ms 32892 KB Output is correct
45 Correct 196 ms 33688 KB Output is correct
46 Correct 189 ms 34844 KB Output is correct
47 Correct 187 ms 32360 KB Output is correct
48 Correct 119 ms 32828 KB Output is correct
49 Correct 102 ms 31812 KB Output is correct
50 Correct 100 ms 22280 KB Output is correct
51 Correct 196 ms 33676 KB Output is correct
52 Correct 158 ms 32780 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9728 KB Output is correct
56 Correct 6 ms 9812 KB Output is correct
57 Correct 6 ms 9868 KB Output is correct
58 Correct 6 ms 9812 KB Output is correct
59 Correct 6 ms 9872 KB Output is correct
60 Correct 6 ms 9824 KB Output is correct
61 Correct 8 ms 9868 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 6 ms 9864 KB Output is correct
64 Correct 6 ms 9956 KB Output is correct
65 Correct 6 ms 9864 KB Output is correct
66 Correct 6 ms 9940 KB Output is correct
67 Correct 136 ms 31776 KB Output is correct
68 Correct 144 ms 33228 KB Output is correct
69 Correct 179 ms 33232 KB Output is correct
70 Correct 167 ms 33848 KB Output is correct
71 Correct 170 ms 33728 KB Output is correct
72 Correct 187 ms 33612 KB Output is correct
73 Correct 163 ms 34764 KB Output is correct
74 Correct 101 ms 30692 KB Output is correct
75 Correct 113 ms 31804 KB Output is correct
76 Correct 173 ms 31124 KB Output is correct
77 Correct 140 ms 33648 KB Output is correct
78 Correct 145 ms 33328 KB Output is correct
79 Correct 130 ms 31816 KB Output is correct
80 Correct 94 ms 31024 KB Output is correct
81 Correct 192 ms 34636 KB Output is correct
82 Correct 193 ms 34640 KB Output is correct
83 Correct 146 ms 35412 KB Output is correct
84 Correct 146 ms 33856 KB Output is correct
85 Correct 192 ms 34660 KB Output is correct
86 Correct 150 ms 31852 KB Output is correct
87 Correct 149 ms 31864 KB Output is correct
88 Correct 156 ms 32184 KB Output is correct
89 Correct 168 ms 32608 KB Output is correct
90 Correct 209 ms 32344 KB Output is correct
91 Correct 194 ms 33052 KB Output is correct
92 Correct 192 ms 33804 KB Output is correct
93 Correct 195 ms 34580 KB Output is correct
94 Correct 193 ms 32388 KB Output is correct
95 Correct 116 ms 32740 KB Output is correct
96 Correct 103 ms 31816 KB Output is correct
97 Correct 98 ms 22344 KB Output is correct
98 Correct 193 ms 33608 KB Output is correct
99 Correct 164 ms 32708 KB Output is correct
100 Correct 44 ms 14124 KB Output is correct
101 Correct 200 ms 33052 KB Output is correct
102 Correct 159 ms 28464 KB Output is correct
103 Correct 160 ms 28616 KB Output is correct
104 Correct 199 ms 31880 KB Output is correct