Submission #1101686

# Submission time Handle Problem Language Result Execution time Memory
1101686 2024-10-16T15:24:55 Z pubin06 Stranded Far From Home (BOI22_island) C++14
100 / 100
97 ms 19380 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define sz(v) (int)(v).size()
using namespace std;

const int MXn = 200005;
const long long oo = 1e18;
const int MOD = 1e9 + 7;

int n, m, a[MXn], s[MXn], par[MXn];
bool cant[MXn];
int find_par(int u) {
	if (u == par[u]) return u;
	int r = find_par(par[u]);
	cant[u] |= cant[par[u]];
	return par[u] = r;
}

signed main(void) {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
    #define TASK ""
    if (ifstream(TASK".INP")) {
    	freopen(TASK".INP", "r", stdin);
    	freopen(TASK".OUT", "w", stdout);
    }
    
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i], s[i] = a[i];
    iota(par + 1, par + 1 + n, 1);
    vector<array<int, 3>> es;
    for (int i = 1, u, v; i <= m; i++) {
    	cin >> u >> v;
    	if (a[u] < a[v]) swap(u, v);
    	es.push_back({a[u], u, v});
    }
    sort(begin(es), end(es));
    for (auto e: es) {
    	int u = e[1], v = e[2];
    	u = find_par(u), v = find_par(v);
    	if (u ^ v) {
    		cant[v] = s[v] < a[u];
    		s[u] += s[v];
    		par[v] = u;
    	}
    }
    for (int i = 1; i <= n; i++) {
    	find_par(i); cout << (cant[i] ? 0 : 1);
    }
    
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:26:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |      freopen(TASK".INP", "r", stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:27:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |      freopen(TASK".OUT", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 1 ms 4672 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 72 ms 15184 KB Output is correct
4 Correct 84 ms 16416 KB Output is correct
5 Correct 69 ms 16064 KB Output is correct
6 Correct 81 ms 16064 KB Output is correct
7 Correct 72 ms 16064 KB Output is correct
8 Correct 87 ms 16188 KB Output is correct
9 Correct 70 ms 16064 KB Output is correct
10 Correct 70 ms 15472 KB Output is correct
11 Correct 71 ms 18356 KB Output is correct
12 Correct 83 ms 14784 KB Output is correct
13 Correct 66 ms 17844 KB Output is correct
14 Correct 72 ms 17588 KB Output is correct
15 Correct 83 ms 16312 KB Output is correct
16 Correct 51 ms 15548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 71 ms 14996 KB Output is correct
3 Correct 75 ms 16096 KB Output is correct
4 Correct 74 ms 19252 KB Output is correct
5 Correct 70 ms 16824 KB Output is correct
6 Correct 77 ms 16084 KB Output is correct
7 Correct 80 ms 16216 KB Output is correct
8 Correct 77 ms 16320 KB Output is correct
9 Correct 52 ms 15392 KB Output is correct
10 Correct 76 ms 18560 KB Output is correct
11 Correct 80 ms 15804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 91 ms 15036 KB Output is correct
3 Correct 97 ms 16072 KB Output is correct
4 Correct 82 ms 16320 KB Output is correct
5 Correct 84 ms 16320 KB Output is correct
6 Correct 78 ms 16076 KB Output is correct
7 Correct 72 ms 17588 KB Output is correct
8 Correct 62 ms 16452 KB Output is correct
9 Correct 70 ms 13760 KB Output is correct
10 Correct 71 ms 14792 KB Output is correct
11 Correct 68 ms 15796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 1 ms 4672 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 72 ms 15184 KB Output is correct
18 Correct 84 ms 16416 KB Output is correct
19 Correct 69 ms 16064 KB Output is correct
20 Correct 81 ms 16064 KB Output is correct
21 Correct 72 ms 16064 KB Output is correct
22 Correct 87 ms 16188 KB Output is correct
23 Correct 70 ms 16064 KB Output is correct
24 Correct 70 ms 15472 KB Output is correct
25 Correct 71 ms 18356 KB Output is correct
26 Correct 83 ms 14784 KB Output is correct
27 Correct 66 ms 17844 KB Output is correct
28 Correct 72 ms 17588 KB Output is correct
29 Correct 83 ms 16312 KB Output is correct
30 Correct 51 ms 15548 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 71 ms 14996 KB Output is correct
33 Correct 75 ms 16096 KB Output is correct
34 Correct 74 ms 19252 KB Output is correct
35 Correct 70 ms 16824 KB Output is correct
36 Correct 77 ms 16084 KB Output is correct
37 Correct 80 ms 16216 KB Output is correct
38 Correct 77 ms 16320 KB Output is correct
39 Correct 52 ms 15392 KB Output is correct
40 Correct 76 ms 18560 KB Output is correct
41 Correct 80 ms 15804 KB Output is correct
42 Correct 1 ms 4432 KB Output is correct
43 Correct 91 ms 15036 KB Output is correct
44 Correct 97 ms 16072 KB Output is correct
45 Correct 82 ms 16320 KB Output is correct
46 Correct 84 ms 16320 KB Output is correct
47 Correct 78 ms 16076 KB Output is correct
48 Correct 72 ms 17588 KB Output is correct
49 Correct 62 ms 16452 KB Output is correct
50 Correct 70 ms 13760 KB Output is correct
51 Correct 71 ms 14792 KB Output is correct
52 Correct 68 ms 15796 KB Output is correct
53 Correct 1 ms 4436 KB Output is correct
54 Correct 1 ms 4436 KB Output is correct
55 Correct 1 ms 4560 KB Output is correct
56 Correct 2 ms 4496 KB Output is correct
57 Correct 2 ms 4940 KB Output is correct
58 Correct 2 ms 4576 KB Output is correct
59 Correct 2 ms 4572 KB Output is correct
60 Correct 2 ms 4856 KB Output is correct
61 Correct 2 ms 4856 KB Output is correct
62 Correct 2 ms 4704 KB Output is correct
63 Correct 2 ms 4692 KB Output is correct
64 Correct 2 ms 4692 KB Output is correct
65 Correct 2 ms 4692 KB Output is correct
66 Correct 2 ms 4692 KB Output is correct
67 Correct 69 ms 16320 KB Output is correct
68 Correct 67 ms 16564 KB Output is correct
69 Correct 70 ms 16072 KB Output is correct
70 Correct 75 ms 16064 KB Output is correct
71 Correct 83 ms 16096 KB Output is correct
72 Correct 86 ms 16188 KB Output is correct
73 Correct 74 ms 16068 KB Output is correct
74 Correct 70 ms 15552 KB Output is correct
75 Correct 82 ms 18208 KB Output is correct
76 Correct 76 ms 14792 KB Output is correct
77 Correct 70 ms 17712 KB Output is correct
78 Correct 80 ms 17592 KB Output is correct
79 Correct 67 ms 16320 KB Output is correct
80 Correct 50 ms 15548 KB Output is correct
81 Correct 73 ms 16064 KB Output is correct
82 Correct 83 ms 16320 KB Output is correct
83 Correct 84 ms 19380 KB Output is correct
84 Correct 70 ms 16656 KB Output is correct
85 Correct 73 ms 16320 KB Output is correct
86 Correct 75 ms 16180 KB Output is correct
87 Correct 70 ms 16320 KB Output is correct
88 Correct 74 ms 18508 KB Output is correct
89 Correct 80 ms 15728 KB Output is correct
90 Correct 97 ms 16072 KB Output is correct
91 Correct 82 ms 16056 KB Output is correct
92 Correct 85 ms 16320 KB Output is correct
93 Correct 80 ms 16328 KB Output is correct
94 Correct 86 ms 16064 KB Output is correct
95 Correct 77 ms 17588 KB Output is correct
96 Correct 66 ms 16572 KB Output is correct
97 Correct 77 ms 13724 KB Output is correct
98 Correct 72 ms 14792 KB Output is correct
99 Correct 75 ms 15800 KB Output is correct
100 Correct 50 ms 13280 KB Output is correct
101 Correct 90 ms 16308 KB Output is correct
102 Correct 81 ms 15284 KB Output is correct
103 Correct 92 ms 15428 KB Output is correct
104 Correct 80 ms 16064 KB Output is correct