Submission #1002485

# Submission time Handle Problem Language Result Execution time Memory
1002485 2024-06-19T15:14:15 Z Andrey Stranded Far From Home (BOI22_island) C++14
100 / 100
144 ms 45040 KB
#include<bits/stdc++.h>
using namespace std;
 
vector<long long> haha[200001];
vector<long long> dsu(200001);
vector<long long> tree[200001];
vector<long long> st(200001);
vector<long long> wow(200001);
vector<bool> ans(200001);
 
long long calc(long long a) {
    long long c = a,e = a;
    while(dsu[c] != c) {
        c = dsu[c];
    }
    while(e != dsu[e]) {
        long long d = dsu[e];
        dsu[e] = c;
        e = d;
    }
    return c;
}
 
void dfs(long long a) {
    st[a] = wow[a];
    for(long long v: tree[a]) {
        dfs(v);
        st[a]+=st[v];
    }
}
 
void dude(long long a) {
    ans[a] = true;
    for(long long v: tree[a]) {
        if(st[v] >= wow[a]) {
            dude(v);
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,m,a,b;
    cin >> n >> m;
    vector<pair<long long,long long>> wut(0);
    for(long long i = 1; i <= n; i++) {
        cin >> wow[i];
        dsu[i] = i;
        wut.push_back({wow[i],i});
    }
    sort(wut.begin(),wut.end());
    vector<int> pos(n+1);
    for(int i = 0; i < n; i++) {
        pos[wut[i].second] = i;
    }
    for(long long i = 0; i < m; i++) {
        cin >> a >> b;
        if(pos[a] > pos[b]) {
            haha[a].push_back(b);
        }
        else {
            haha[b].push_back(a);
        }
    }
    for(long long i = 0; i < wut.size(); i++) {
        long long a = wut[i].second;
        for(long long v: haha[a]) {
            if(calc(v) != calc(a)) {
                tree[a].push_back(calc(v));
                dsu[calc(v)] = a;
            }
        }
    }
    dfs(wut[n-1].second);
    dude(wut[n-1].second);
    for(long long i = 1; i <= n; i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:68:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(long long i = 0; i < wut.size(); i++) {
      |                          ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14424 KB Output is correct
2 Correct 5 ms 14424 KB Output is correct
3 Correct 6 ms 14476 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14684 KB Output is correct
6 Correct 7 ms 14684 KB Output is correct
7 Correct 6 ms 14692 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 6 ms 14680 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 6 ms 14508 KB Output is correct
13 Correct 6 ms 14680 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 6 ms 14528 KB Output is correct
3 Correct 87 ms 35624 KB Output is correct
4 Correct 89 ms 42688 KB Output is correct
5 Correct 97 ms 31056 KB Output is correct
6 Correct 101 ms 31476 KB Output is correct
7 Correct 107 ms 31428 KB Output is correct
8 Correct 106 ms 45000 KB Output is correct
9 Correct 74 ms 29276 KB Output is correct
10 Correct 61 ms 28352 KB Output is correct
11 Correct 107 ms 43780 KB Output is correct
12 Correct 110 ms 34240 KB Output is correct
13 Correct 82 ms 43460 KB Output is correct
14 Correct 87 ms 42556 KB Output is correct
15 Correct 95 ms 45000 KB Output is correct
16 Correct 74 ms 43988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 108 ms 31264 KB Output is correct
3 Correct 115 ms 31436 KB Output is correct
4 Correct 105 ms 45040 KB Output is correct
5 Correct 79 ms 40444 KB Output is correct
6 Correct 110 ms 31504 KB Output is correct
7 Correct 107 ms 44992 KB Output is correct
8 Correct 100 ms 44996 KB Output is correct
9 Correct 69 ms 44068 KB Output is correct
10 Correct 83 ms 33312 KB Output is correct
11 Correct 87 ms 31756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 124 ms 31964 KB Output is correct
3 Correct 135 ms 31428 KB Output is correct
4 Correct 131 ms 31424 KB Output is correct
5 Correct 118 ms 31484 KB Output is correct
6 Correct 126 ms 32120 KB Output is correct
7 Correct 81 ms 36348 KB Output is correct
8 Correct 69 ms 43896 KB Output is correct
9 Correct 73 ms 25632 KB Output is correct
10 Correct 91 ms 29896 KB Output is correct
11 Correct 91 ms 31684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14424 KB Output is correct
2 Correct 5 ms 14424 KB Output is correct
3 Correct 6 ms 14476 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14684 KB Output is correct
6 Correct 7 ms 14684 KB Output is correct
7 Correct 6 ms 14692 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 6 ms 14680 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 6 ms 14508 KB Output is correct
13 Correct 6 ms 14680 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 6 ms 14528 KB Output is correct
17 Correct 87 ms 35624 KB Output is correct
18 Correct 89 ms 42688 KB Output is correct
19 Correct 97 ms 31056 KB Output is correct
20 Correct 101 ms 31476 KB Output is correct
21 Correct 107 ms 31428 KB Output is correct
22 Correct 106 ms 45000 KB Output is correct
23 Correct 74 ms 29276 KB Output is correct
24 Correct 61 ms 28352 KB Output is correct
25 Correct 107 ms 43780 KB Output is correct
26 Correct 110 ms 34240 KB Output is correct
27 Correct 82 ms 43460 KB Output is correct
28 Correct 87 ms 42556 KB Output is correct
29 Correct 95 ms 45000 KB Output is correct
30 Correct 74 ms 43988 KB Output is correct
31 Correct 7 ms 14428 KB Output is correct
32 Correct 108 ms 31264 KB Output is correct
33 Correct 115 ms 31436 KB Output is correct
34 Correct 105 ms 45040 KB Output is correct
35 Correct 79 ms 40444 KB Output is correct
36 Correct 110 ms 31504 KB Output is correct
37 Correct 107 ms 44992 KB Output is correct
38 Correct 100 ms 44996 KB Output is correct
39 Correct 69 ms 44068 KB Output is correct
40 Correct 83 ms 33312 KB Output is correct
41 Correct 87 ms 31756 KB Output is correct
42 Correct 5 ms 14428 KB Output is correct
43 Correct 124 ms 31964 KB Output is correct
44 Correct 135 ms 31428 KB Output is correct
45 Correct 131 ms 31424 KB Output is correct
46 Correct 118 ms 31484 KB Output is correct
47 Correct 126 ms 32120 KB Output is correct
48 Correct 81 ms 36348 KB Output is correct
49 Correct 69 ms 43896 KB Output is correct
50 Correct 73 ms 25632 KB Output is correct
51 Correct 91 ms 29896 KB Output is correct
52 Correct 91 ms 31684 KB Output is correct
53 Correct 5 ms 14428 KB Output is correct
54 Correct 6 ms 14428 KB Output is correct
55 Correct 5 ms 14428 KB Output is correct
56 Correct 6 ms 14680 KB Output is correct
57 Correct 6 ms 14684 KB Output is correct
58 Correct 6 ms 14684 KB Output is correct
59 Correct 6 ms 14600 KB Output is correct
60 Correct 6 ms 14680 KB Output is correct
61 Correct 6 ms 14684 KB Output is correct
62 Correct 6 ms 14684 KB Output is correct
63 Correct 6 ms 14684 KB Output is correct
64 Correct 6 ms 14684 KB Output is correct
65 Correct 6 ms 14796 KB Output is correct
66 Correct 6 ms 14684 KB Output is correct
67 Correct 87 ms 35672 KB Output is correct
68 Correct 89 ms 42688 KB Output is correct
69 Correct 110 ms 30820 KB Output is correct
70 Correct 107 ms 31432 KB Output is correct
71 Correct 100 ms 31428 KB Output is correct
72 Correct 108 ms 44992 KB Output is correct
73 Correct 73 ms 29100 KB Output is correct
74 Correct 60 ms 28356 KB Output is correct
75 Correct 106 ms 43800 KB Output is correct
76 Correct 105 ms 33988 KB Output is correct
77 Correct 81 ms 43276 KB Output is correct
78 Correct 104 ms 42696 KB Output is correct
79 Correct 90 ms 44992 KB Output is correct
80 Correct 70 ms 43920 KB Output is correct
81 Correct 117 ms 31168 KB Output is correct
82 Correct 144 ms 31424 KB Output is correct
83 Correct 106 ms 44992 KB Output is correct
84 Correct 103 ms 40384 KB Output is correct
85 Correct 116 ms 31404 KB Output is correct
86 Correct 108 ms 44996 KB Output is correct
87 Correct 106 ms 44988 KB Output is correct
88 Correct 84 ms 33428 KB Output is correct
89 Correct 89 ms 31684 KB Output is correct
90 Correct 135 ms 31876 KB Output is correct
91 Correct 119 ms 31424 KB Output is correct
92 Correct 122 ms 31432 KB Output is correct
93 Correct 125 ms 31728 KB Output is correct
94 Correct 112 ms 32196 KB Output is correct
95 Correct 104 ms 36544 KB Output is correct
96 Correct 71 ms 43708 KB Output is correct
97 Correct 70 ms 25488 KB Output is correct
98 Correct 93 ms 29884 KB Output is correct
99 Correct 87 ms 31688 KB Output is correct
100 Correct 31 ms 19280 KB Output is correct
101 Correct 121 ms 31428 KB Output is correct
102 Correct 103 ms 31688 KB Output is correct
103 Correct 121 ms 32196 KB Output is correct
104 Correct 131 ms 32364 KB Output is correct