Submission #860988

# Submission time Handle Problem Language Result Execution time Memory
860988 2023-10-15T04:30:03 Z Cookie Stranded Far From Home (BOI22_island) C++14
100 / 100
90 ms 18096 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
ifstream fin("store.inp");
ofstream fout("store.out");
const ll mxn = 3e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
//const int x[4] = {0, -1, 0, 1};
int n, m;
struct E{
    ll u, v, w;
    bool operator <(const E &b){
        return(w < b.w);
    }
};
vt<E>edge;
bool bad[mxn + 1];
int pa[mxn + 1]; 
ll sm[mxn + 1], c[mxn + 1];
int fp(int u){
    if(pa[u] == u)return(u);
    int v = fp(pa[u]);
    bad[u] |= bad[pa[u]]; pa[u] = v;
    return(v);
}
void unon(int u, int v){
    u = fp(u); v = fp(v);
    if(u == v)return;
    if(c[u] < c[v])swap(u, v);  
    if(c[u] > sm[v])bad[v] = 1;
    pa[v] = u; sm[u] += sm[v];
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> c[i]; pa[i] = i; sm[i] = c[i];
    }
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        edge.pb({u, v, max(c[u], c[v])});
    }
    sort(edge.begin(), edge.end());
    for(auto [u, v, w]: edge){
        unon(u, v);
    }
    for(int i = 1; i <= n; i++){
        //cout << bad[i] << " " << pa[i] << "\n";
    }
    for(int i = 1; i <= n; i++){
        fp(i);
        cout << !bad[i];
    }
    return(0);
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [u, v, w]: edge){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2660 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2668 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 84 ms 12228 KB Output is correct
4 Correct 55 ms 11984 KB Output is correct
5 Correct 76 ms 17460 KB Output is correct
6 Correct 70 ms 17164 KB Output is correct
7 Correct 73 ms 16260 KB Output is correct
8 Correct 67 ms 17244 KB Output is correct
9 Correct 72 ms 16604 KB Output is correct
10 Correct 57 ms 15204 KB Output is correct
11 Correct 59 ms 16588 KB Output is correct
12 Correct 59 ms 15364 KB Output is correct
13 Correct 55 ms 14140 KB Output is correct
14 Correct 56 ms 15300 KB Output is correct
15 Correct 70 ms 16124 KB Output is correct
16 Correct 51 ms 14788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 73 ms 12972 KB Output is correct
3 Correct 74 ms 15816 KB Output is correct
4 Correct 61 ms 16836 KB Output is correct
5 Correct 54 ms 15816 KB Output is correct
6 Correct 73 ms 17096 KB Output is correct
7 Correct 69 ms 16888 KB Output is correct
8 Correct 68 ms 16840 KB Output is correct
9 Correct 50 ms 16080 KB Output is correct
10 Correct 63 ms 15816 KB Output is correct
11 Correct 58 ms 14280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 71 ms 12488 KB Output is correct
3 Correct 70 ms 15796 KB Output is correct
4 Correct 72 ms 16184 KB Output is correct
5 Correct 67 ms 16656 KB Output is correct
6 Correct 68 ms 15948 KB Output is correct
7 Correct 67 ms 17256 KB Output is correct
8 Correct 56 ms 14532 KB Output is correct
9 Correct 51 ms 14788 KB Output is correct
10 Correct 60 ms 14280 KB Output is correct
11 Correct 57 ms 15764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2660 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2668 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 84 ms 12228 KB Output is correct
18 Correct 55 ms 11984 KB Output is correct
19 Correct 76 ms 17460 KB Output is correct
20 Correct 70 ms 17164 KB Output is correct
21 Correct 73 ms 16260 KB Output is correct
22 Correct 67 ms 17244 KB Output is correct
23 Correct 72 ms 16604 KB Output is correct
24 Correct 57 ms 15204 KB Output is correct
25 Correct 59 ms 16588 KB Output is correct
26 Correct 59 ms 15364 KB Output is correct
27 Correct 55 ms 14140 KB Output is correct
28 Correct 56 ms 15300 KB Output is correct
29 Correct 70 ms 16124 KB Output is correct
30 Correct 51 ms 14788 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 73 ms 12972 KB Output is correct
33 Correct 74 ms 15816 KB Output is correct
34 Correct 61 ms 16836 KB Output is correct
35 Correct 54 ms 15816 KB Output is correct
36 Correct 73 ms 17096 KB Output is correct
37 Correct 69 ms 16888 KB Output is correct
38 Correct 68 ms 16840 KB Output is correct
39 Correct 50 ms 16080 KB Output is correct
40 Correct 63 ms 15816 KB Output is correct
41 Correct 58 ms 14280 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 71 ms 12488 KB Output is correct
44 Correct 70 ms 15796 KB Output is correct
45 Correct 72 ms 16184 KB Output is correct
46 Correct 67 ms 16656 KB Output is correct
47 Correct 68 ms 15948 KB Output is correct
48 Correct 67 ms 17256 KB Output is correct
49 Correct 56 ms 14532 KB Output is correct
50 Correct 51 ms 14788 KB Output is correct
51 Correct 60 ms 14280 KB Output is correct
52 Correct 57 ms 15764 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 1 ms 2652 KB Output is correct
58 Correct 2 ms 2652 KB Output is correct
59 Correct 1 ms 2652 KB Output is correct
60 Correct 1 ms 2648 KB Output is correct
61 Correct 1 ms 2652 KB Output is correct
62 Correct 1 ms 2652 KB Output is correct
63 Correct 1 ms 2904 KB Output is correct
64 Correct 1 ms 2652 KB Output is correct
65 Correct 1 ms 2652 KB Output is correct
66 Correct 1 ms 2904 KB Output is correct
67 Correct 72 ms 16224 KB Output is correct
68 Correct 56 ms 14536 KB Output is correct
69 Correct 74 ms 16840 KB Output is correct
70 Correct 74 ms 15704 KB Output is correct
71 Correct 71 ms 15840 KB Output is correct
72 Correct 66 ms 16072 KB Output is correct
73 Correct 67 ms 17272 KB Output is correct
74 Correct 58 ms 15844 KB Output is correct
75 Correct 75 ms 16580 KB Output is correct
76 Correct 63 ms 15824 KB Output is correct
77 Correct 55 ms 14656 KB Output is correct
78 Correct 54 ms 15304 KB Output is correct
79 Correct 80 ms 16840 KB Output is correct
80 Correct 51 ms 16484 KB Output is correct
81 Correct 75 ms 16072 KB Output is correct
82 Correct 72 ms 17200 KB Output is correct
83 Correct 61 ms 16584 KB Output is correct
84 Correct 70 ms 14792 KB Output is correct
85 Correct 75 ms 16580 KB Output is correct
86 Correct 69 ms 16960 KB Output is correct
87 Correct 71 ms 16244 KB Output is correct
88 Correct 74 ms 15540 KB Output is correct
89 Correct 58 ms 15048 KB Output is correct
90 Correct 72 ms 16072 KB Output is correct
91 Correct 74 ms 17096 KB Output is correct
92 Correct 72 ms 16032 KB Output is correct
93 Correct 66 ms 16648 KB Output is correct
94 Correct 83 ms 16068 KB Output is correct
95 Correct 65 ms 18096 KB Output is correct
96 Correct 58 ms 15304 KB Output is correct
97 Correct 52 ms 15044 KB Output is correct
98 Correct 59 ms 15300 KB Output is correct
99 Correct 58 ms 14256 KB Output is correct
100 Correct 39 ms 11204 KB Output is correct
101 Correct 80 ms 16360 KB Output is correct
102 Correct 70 ms 14980 KB Output is correct
103 Correct 79 ms 15300 KB Output is correct
104 Correct 90 ms 16580 KB Output is correct