Submission #654549

# Submission time Handle Problem Language Result Execution time Memory
654549 2022-10-31T16:39:19 Z Lobo Stranded Far From Home (BOI22_island) C++17
100 / 100
178 ms 37036 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e5+10;

int n, m, s[maxn], ds[maxn], dsz[maxn], dss[maxn], ans[maxn];
vector<int> win[maxn];

int find(int u) {
    if(u == ds[u]) return u;
    return ds[u] = find(ds[u]);
}

void join(int u, int v) {
    if(dsz[u] < dsz[v]) swap(u,v);
    dsz[u]+= dsz[v];
    dss[u]+= dss[v];
    ds[v] = u;
    for(auto x : win[v]) win[u].pb(x);
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> s[i];
        dss[i] = s[i];
        ds[i] = i;
        dsz[i] = 1;
        win[i].pb(i);
    }
    vector<pair<int,pair<int,int>>> edgs;
    for(int i = 1; i <= m; i++) {
        int u,v; cin >> u >> v;
        if(s[u] < s[v]) swap(u,v);
        edgs.pb(mp(s[u],mp(u,v)));
    }

    sort(all(edgs));
    for(auto X : edgs) {
        int smx = X.fr;
        int u = X.sc.fr;
        int v = X.sc.sc;

        if(dss[find(v)] < s[u]) {
            win[find(v)].clear();
        }
        if(find(u) != find(v)) join(find(u),find(v));
    }

    for(auto x : win[find(1)]) {
        ans[x] = 1;
    }
    for(int i = 1; i <= n; i++) {
        cout << ans[i];
    }cout << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

island.cpp: In function 'void solve()':
island.cpp:50:13: warning: unused variable 'smx' [-Wunused-variable]
   50 |         int smx = X.fr;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5168 KB Output is correct
7 Correct 4 ms 5268 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 6 ms 5204 KB Output is correct
10 Correct 4 ms 5332 KB Output is correct
11 Correct 4 ms 5332 KB Output is correct
12 Correct 5 ms 5332 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 126 ms 30164 KB Output is correct
4 Correct 119 ms 27972 KB Output is correct
5 Correct 148 ms 32164 KB Output is correct
6 Correct 160 ms 33248 KB Output is correct
7 Correct 171 ms 33348 KB Output is correct
8 Correct 136 ms 30332 KB Output is correct
9 Correct 132 ms 37036 KB Output is correct
10 Correct 112 ms 25424 KB Output is correct
11 Correct 124 ms 29468 KB Output is correct
12 Correct 137 ms 26768 KB Output is correct
13 Correct 110 ms 27968 KB Output is correct
14 Correct 114 ms 27868 KB Output is correct
15 Correct 124 ms 30336 KB Output is correct
16 Correct 94 ms 29388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 158 ms 35152 KB Output is correct
3 Correct 160 ms 35372 KB Output is correct
4 Correct 115 ms 30700 KB Output is correct
5 Correct 111 ms 27568 KB Output is correct
6 Correct 170 ms 34980 KB Output is correct
7 Correct 121 ms 30536 KB Output is correct
8 Correct 125 ms 30688 KB Output is correct
9 Correct 82 ms 29580 KB Output is correct
10 Correct 119 ms 27984 KB Output is correct
11 Correct 133 ms 27916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 164 ms 30736 KB Output is correct
3 Correct 160 ms 31396 KB Output is correct
4 Correct 164 ms 33700 KB Output is correct
5 Correct 161 ms 36280 KB Output is correct
6 Correct 170 ms 32256 KB Output is correct
7 Correct 117 ms 30564 KB Output is correct
8 Correct 93 ms 27164 KB Output is correct
9 Correct 99 ms 20232 KB Output is correct
10 Correct 178 ms 35300 KB Output is correct
11 Correct 123 ms 27820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5168 KB Output is correct
7 Correct 4 ms 5268 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 6 ms 5204 KB Output is correct
10 Correct 4 ms 5332 KB Output is correct
11 Correct 4 ms 5332 KB Output is correct
12 Correct 5 ms 5332 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5224 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 126 ms 30164 KB Output is correct
18 Correct 119 ms 27972 KB Output is correct
19 Correct 148 ms 32164 KB Output is correct
20 Correct 160 ms 33248 KB Output is correct
21 Correct 171 ms 33348 KB Output is correct
22 Correct 136 ms 30332 KB Output is correct
23 Correct 132 ms 37036 KB Output is correct
24 Correct 112 ms 25424 KB Output is correct
25 Correct 124 ms 29468 KB Output is correct
26 Correct 137 ms 26768 KB Output is correct
27 Correct 110 ms 27968 KB Output is correct
28 Correct 114 ms 27868 KB Output is correct
29 Correct 124 ms 30336 KB Output is correct
30 Correct 94 ms 29388 KB Output is correct
31 Correct 4 ms 4948 KB Output is correct
32 Correct 158 ms 35152 KB Output is correct
33 Correct 160 ms 35372 KB Output is correct
34 Correct 115 ms 30700 KB Output is correct
35 Correct 111 ms 27568 KB Output is correct
36 Correct 170 ms 34980 KB Output is correct
37 Correct 121 ms 30536 KB Output is correct
38 Correct 125 ms 30688 KB Output is correct
39 Correct 82 ms 29580 KB Output is correct
40 Correct 119 ms 27984 KB Output is correct
41 Correct 133 ms 27916 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 164 ms 30736 KB Output is correct
44 Correct 160 ms 31396 KB Output is correct
45 Correct 164 ms 33700 KB Output is correct
46 Correct 161 ms 36280 KB Output is correct
47 Correct 170 ms 32256 KB Output is correct
48 Correct 117 ms 30564 KB Output is correct
49 Correct 93 ms 27164 KB Output is correct
50 Correct 99 ms 20232 KB Output is correct
51 Correct 178 ms 35300 KB Output is correct
52 Correct 123 ms 27820 KB Output is correct
53 Correct 3 ms 5032 KB Output is correct
54 Correct 3 ms 5028 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 4 ms 5300 KB Output is correct
57 Correct 4 ms 5292 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 4 ms 5204 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 5 ms 5204 KB Output is correct
62 Correct 5 ms 5332 KB Output is correct
63 Correct 5 ms 5332 KB Output is correct
64 Correct 4 ms 5332 KB Output is correct
65 Correct 5 ms 5204 KB Output is correct
66 Correct 4 ms 5204 KB Output is correct
67 Correct 115 ms 29740 KB Output is correct
68 Correct 107 ms 27944 KB Output is correct
69 Correct 147 ms 32028 KB Output is correct
70 Correct 144 ms 33108 KB Output is correct
71 Correct 151 ms 33140 KB Output is correct
72 Correct 134 ms 30316 KB Output is correct
73 Correct 117 ms 36948 KB Output is correct
74 Correct 105 ms 25440 KB Output is correct
75 Correct 110 ms 29476 KB Output is correct
76 Correct 134 ms 26908 KB Output is correct
77 Correct 106 ms 27948 KB Output is correct
78 Correct 107 ms 27948 KB Output is correct
79 Correct 116 ms 30252 KB Output is correct
80 Correct 80 ms 29356 KB Output is correct
81 Correct 151 ms 34892 KB Output is correct
82 Correct 153 ms 35084 KB Output is correct
83 Correct 115 ms 30400 KB Output is correct
84 Correct 104 ms 27628 KB Output is correct
85 Correct 160 ms 34824 KB Output is correct
86 Correct 122 ms 30444 KB Output is correct
87 Correct 113 ms 30388 KB Output is correct
88 Correct 115 ms 27840 KB Output is correct
89 Correct 124 ms 27856 KB Output is correct
90 Correct 160 ms 30452 KB Output is correct
91 Correct 159 ms 31256 KB Output is correct
92 Correct 166 ms 33556 KB Output is correct
93 Correct 176 ms 36108 KB Output is correct
94 Correct 173 ms 32068 KB Output is correct
95 Correct 126 ms 30380 KB Output is correct
96 Correct 94 ms 27052 KB Output is correct
97 Correct 94 ms 20124 KB Output is correct
98 Correct 178 ms 35284 KB Output is correct
99 Correct 142 ms 27944 KB Output is correct
100 Correct 60 ms 12976 KB Output is correct
101 Correct 163 ms 32068 KB Output is correct
102 Correct 143 ms 27404 KB Output is correct
103 Correct 142 ms 25816 KB Output is correct
104 Correct 157 ms 28912 KB Output is correct