답안 #829410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829410 2023-08-18T10:23:22 Z QwertyPi Stranded Far From Home (BOI22_island) C++14
100 / 100
338 ms 72420 KB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#define int long long

using namespace std;

const int N = 2e5 + 11;
const int LGN = 20;
int a[N], p[N];

struct edge{
	int u, v;
};

struct DSU{
    int dsu[N];
    void init(int n){
        for(int i = 0; i <= n; i++) dsu[i] = i;
    }
    int f(int x){ return dsu[x] == x ? x : dsu[x] = f(dsu[x]); }
    void g(int x, int y){ x = f(x); y = f(y); dsu[x] = y; }
    bool sa(int x, int y){ return f(x) == f(y); }
} dsu;

vector<int> G[N];
int st[N], bl[LGN][N];

void add_edge(int u, int v){
	G[v].push_back(u);
}

void dfs(int v, int pa = -1){
	st[v] = a[v];
	for(auto u : G[v]){
		dfs(u, v); st[v] += st[u];
	}
}

void dfs2(int v, int pa = -1){
	st[v] = a[v];
	for(auto u : G[v]){
		bl[0][u] = st[u] >= a[v] ? v : u;
		for(int j = 1; j < LGN; j++){
			bl[j][u] = bl[j - 1][bl[j - 1][u]];
		}
		dfs2(u, v);
	}
}

int32_t main(){
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	vector<edge> E;
	vector<pair<int, int>> ord;
	for(int i = 1; i <= n; i++) ord.push_back({a[i], i});
	sort(ord.begin(), ord.end());
	for(int i = 1; i <= n; i++) p[ord[i - 1].second] = i;
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v; if(p[u] > p[v]) swap(u, v);
		E.push_back({u, v});
	}
	sort(E.begin(), E.end(), [](edge e1, edge e2){ return p[e1.v] < p[e2.v]; });

	dsu.init(n);
	for(auto [u, v] : E){
		if(dsu.sa(u, v)) continue;
		add_edge(dsu.f(u), v); dsu.g(u, v);
	}

	int rt = dsu.f(1);
	dfs(rt); dfs2(rt);
	for(int i = 1; i <= n; i++){
		cout << (bl[LGN - 1][i] == 0 ? "1" : "0");
	}
	cout << endl;
}

Compilation message

island.cpp: In function 'int32_t main()':
island.cpp:66:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |  for(auto [u, v] : E){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 2 ms 5076 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 4 ms 5588 KB Output is correct
5 Correct 5 ms 5588 KB Output is correct
6 Correct 4 ms 5588 KB Output is correct
7 Correct 4 ms 5588 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 5 ms 5716 KB Output is correct
10 Correct 4 ms 5588 KB Output is correct
11 Correct 4 ms 5588 KB Output is correct
12 Correct 4 ms 5588 KB Output is correct
13 Correct 4 ms 5716 KB Output is correct
14 Correct 4 ms 5588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5144 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 252 ms 62824 KB Output is correct
4 Correct 184 ms 69568 KB Output is correct
5 Correct 294 ms 55988 KB Output is correct
6 Correct 271 ms 57560 KB Output is correct
7 Correct 306 ms 57656 KB Output is correct
8 Correct 217 ms 72196 KB Output is correct
9 Correct 214 ms 56404 KB Output is correct
10 Correct 207 ms 56244 KB Output is correct
11 Correct 205 ms 71164 KB Output is correct
12 Correct 260 ms 58956 KB Output is correct
13 Correct 189 ms 70844 KB Output is correct
14 Correct 181 ms 69592 KB Output is correct
15 Correct 210 ms 72344 KB Output is correct
16 Correct 212 ms 70916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 238 ms 57404 KB Output is correct
3 Correct 243 ms 57624 KB Output is correct
4 Correct 267 ms 72240 KB Output is correct
5 Correct 178 ms 66736 KB Output is correct
6 Correct 243 ms 57632 KB Output is correct
7 Correct 237 ms 72220 KB Output is correct
8 Correct 242 ms 72284 KB Output is correct
9 Correct 197 ms 70960 KB Output is correct
10 Correct 207 ms 62184 KB Output is correct
11 Correct 211 ms 58448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 320 ms 58228 KB Output is correct
3 Correct 308 ms 57628 KB Output is correct
4 Correct 297 ms 57732 KB Output is correct
5 Correct 301 ms 57828 KB Output is correct
6 Correct 316 ms 56964 KB Output is correct
7 Correct 206 ms 64484 KB Output is correct
8 Correct 193 ms 71084 KB Output is correct
9 Correct 174 ms 34364 KB Output is correct
10 Correct 266 ms 56244 KB Output is correct
11 Correct 199 ms 58464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 2 ms 5076 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 4 ms 5588 KB Output is correct
5 Correct 5 ms 5588 KB Output is correct
6 Correct 4 ms 5588 KB Output is correct
7 Correct 4 ms 5588 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 5 ms 5716 KB Output is correct
10 Correct 4 ms 5588 KB Output is correct
11 Correct 4 ms 5588 KB Output is correct
12 Correct 4 ms 5588 KB Output is correct
13 Correct 4 ms 5716 KB Output is correct
14 Correct 4 ms 5588 KB Output is correct
15 Correct 2 ms 5144 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 252 ms 62824 KB Output is correct
18 Correct 184 ms 69568 KB Output is correct
19 Correct 294 ms 55988 KB Output is correct
20 Correct 271 ms 57560 KB Output is correct
21 Correct 306 ms 57656 KB Output is correct
22 Correct 217 ms 72196 KB Output is correct
23 Correct 214 ms 56404 KB Output is correct
24 Correct 207 ms 56244 KB Output is correct
25 Correct 205 ms 71164 KB Output is correct
26 Correct 260 ms 58956 KB Output is correct
27 Correct 189 ms 70844 KB Output is correct
28 Correct 181 ms 69592 KB Output is correct
29 Correct 210 ms 72344 KB Output is correct
30 Correct 212 ms 70916 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 238 ms 57404 KB Output is correct
33 Correct 243 ms 57624 KB Output is correct
34 Correct 267 ms 72240 KB Output is correct
35 Correct 178 ms 66736 KB Output is correct
36 Correct 243 ms 57632 KB Output is correct
37 Correct 237 ms 72220 KB Output is correct
38 Correct 242 ms 72284 KB Output is correct
39 Correct 197 ms 70960 KB Output is correct
40 Correct 207 ms 62184 KB Output is correct
41 Correct 211 ms 58448 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 320 ms 58228 KB Output is correct
44 Correct 308 ms 57628 KB Output is correct
45 Correct 297 ms 57732 KB Output is correct
46 Correct 301 ms 57828 KB Output is correct
47 Correct 316 ms 56964 KB Output is correct
48 Correct 206 ms 64484 KB Output is correct
49 Correct 193 ms 71084 KB Output is correct
50 Correct 174 ms 34364 KB Output is correct
51 Correct 266 ms 56244 KB Output is correct
52 Correct 199 ms 58464 KB Output is correct
53 Correct 2 ms 5076 KB Output is correct
54 Correct 2 ms 5076 KB Output is correct
55 Correct 2 ms 4984 KB Output is correct
56 Correct 4 ms 5588 KB Output is correct
57 Correct 5 ms 5672 KB Output is correct
58 Correct 4 ms 5588 KB Output is correct
59 Correct 4 ms 5588 KB Output is correct
60 Correct 5 ms 5460 KB Output is correct
61 Correct 4 ms 5716 KB Output is correct
62 Correct 4 ms 5588 KB Output is correct
63 Correct 5 ms 5588 KB Output is correct
64 Correct 4 ms 5588 KB Output is correct
65 Correct 4 ms 5716 KB Output is correct
66 Correct 4 ms 5588 KB Output is correct
67 Correct 264 ms 62856 KB Output is correct
68 Correct 183 ms 69568 KB Output is correct
69 Correct 270 ms 56060 KB Output is correct
70 Correct 283 ms 57520 KB Output is correct
71 Correct 292 ms 57712 KB Output is correct
72 Correct 218 ms 72212 KB Output is correct
73 Correct 233 ms 56480 KB Output is correct
74 Correct 201 ms 56236 KB Output is correct
75 Correct 237 ms 71240 KB Output is correct
76 Correct 270 ms 59048 KB Output is correct
77 Correct 187 ms 70648 KB Output is correct
78 Correct 181 ms 69652 KB Output is correct
79 Correct 235 ms 72220 KB Output is correct
80 Correct 177 ms 70996 KB Output is correct
81 Correct 246 ms 57420 KB Output is correct
82 Correct 283 ms 57624 KB Output is correct
83 Correct 229 ms 72368 KB Output is correct
84 Correct 171 ms 66608 KB Output is correct
85 Correct 242 ms 57544 KB Output is correct
86 Correct 265 ms 72420 KB Output is correct
87 Correct 255 ms 72300 KB Output is correct
88 Correct 198 ms 62200 KB Output is correct
89 Correct 202 ms 58460 KB Output is correct
90 Correct 316 ms 58316 KB Output is correct
91 Correct 312 ms 57744 KB Output is correct
92 Correct 304 ms 57708 KB Output is correct
93 Correct 338 ms 57816 KB Output is correct
94 Correct 265 ms 56964 KB Output is correct
95 Correct 209 ms 64492 KB Output is correct
96 Correct 181 ms 71068 KB Output is correct
97 Correct 165 ms 34436 KB Output is correct
98 Correct 248 ms 56212 KB Output is correct
99 Correct 198 ms 58524 KB Output is correct
100 Correct 110 ms 11572 KB Output is correct
101 Correct 304 ms 57716 KB Output is correct
102 Correct 235 ms 51100 KB Output is correct
103 Correct 330 ms 53368 KB Output is correct
104 Correct 307 ms 58140 KB Output is correct