답안 #603243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603243 2022-07-23T18:10:08 Z CSQ31 Stranded Far From Home (BOI22_island) C++17
100 / 100
178 ms 30804 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define pb push_back
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int ll;
const int MAXN = 2e5+5;
int s[MAXN],par[MAXN];
ll sum[MAXN];
vector<int>adj[MAXN],g[MAXN];
bool good[MAXN];
int find(int x){
	if(x==par[x])return x;
	return par[x] = find(par[x]);
	
}
int main()
{
	owo
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>s[i];
	vector<array<int,3>>e;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		if(s[a] > s[b])swap(a,b);
		e.pb({s[b],a,b});
	}
	for(int i=0;i<n;i++){
		par[i] = i;
		sum[i] = s[i];
		good[i] = 1;
		g[i].pb(i);
	}
	sort(all(e));
	for(auto x:e){
		int v = x[1];
		int u = x[2];
		if(find(v) == find(u))continue;
		if(sum[par[v]] < s[u]){
			for(int x:g[par[v]])good[x] = 0;
			g[par[v]].clear();
		}
		v = find(v);
		u = find(u);
		if(sz(g[v]) > sz(g[u]))swap(v,u);
		sum[u]+=sum[v];
		for(int x:g[v])g[u].pb(x);
		par[v] = u;
	}
	for(int i=0;i<n;i++)cout<<good[i];
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9788 KB Output is correct
5 Correct 7 ms 9784 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9788 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9904 KB Output is correct
12 Correct 6 ms 9872 KB Output is correct
13 Correct 6 ms 9816 KB Output is correct
14 Correct 7 ms 9864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9740 KB Output is correct
3 Correct 113 ms 25468 KB Output is correct
4 Correct 99 ms 25140 KB Output is correct
5 Correct 124 ms 26096 KB Output is correct
6 Correct 136 ms 27092 KB Output is correct
7 Correct 131 ms 27928 KB Output is correct
8 Correct 130 ms 26292 KB Output is correct
9 Correct 121 ms 29496 KB Output is correct
10 Correct 102 ms 24884 KB Output is correct
11 Correct 109 ms 26540 KB Output is correct
12 Correct 118 ms 25020 KB Output is correct
13 Correct 108 ms 24848 KB Output is correct
14 Correct 105 ms 25908 KB Output is correct
15 Correct 113 ms 27188 KB Output is correct
16 Correct 85 ms 26140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 158 ms 28860 KB Output is correct
3 Correct 152 ms 28576 KB Output is correct
4 Correct 114 ms 27188 KB Output is correct
5 Correct 99 ms 26040 KB Output is correct
6 Correct 146 ms 29112 KB Output is correct
7 Correct 119 ms 26988 KB Output is correct
8 Correct 107 ms 26944 KB Output is correct
9 Correct 85 ms 25924 KB Output is correct
10 Correct 121 ms 24464 KB Output is correct
11 Correct 178 ms 26064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 162 ms 26648 KB Output is correct
3 Correct 153 ms 28420 KB Output is correct
4 Correct 149 ms 26284 KB Output is correct
5 Correct 144 ms 30804 KB Output is correct
6 Correct 143 ms 27996 KB Output is correct
7 Correct 124 ms 27852 KB Output is correct
8 Correct 98 ms 26396 KB Output is correct
9 Correct 101 ms 19816 KB Output is correct
10 Correct 146 ms 29248 KB Output is correct
11 Correct 125 ms 25272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 6 ms 9788 KB Output is correct
5 Correct 7 ms 9784 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9788 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9904 KB Output is correct
12 Correct 6 ms 9872 KB Output is correct
13 Correct 6 ms 9816 KB Output is correct
14 Correct 7 ms 9864 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9740 KB Output is correct
17 Correct 113 ms 25468 KB Output is correct
18 Correct 99 ms 25140 KB Output is correct
19 Correct 124 ms 26096 KB Output is correct
20 Correct 136 ms 27092 KB Output is correct
21 Correct 131 ms 27928 KB Output is correct
22 Correct 130 ms 26292 KB Output is correct
23 Correct 121 ms 29496 KB Output is correct
24 Correct 102 ms 24884 KB Output is correct
25 Correct 109 ms 26540 KB Output is correct
26 Correct 118 ms 25020 KB Output is correct
27 Correct 108 ms 24848 KB Output is correct
28 Correct 105 ms 25908 KB Output is correct
29 Correct 113 ms 27188 KB Output is correct
30 Correct 85 ms 26140 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 158 ms 28860 KB Output is correct
33 Correct 152 ms 28576 KB Output is correct
34 Correct 114 ms 27188 KB Output is correct
35 Correct 99 ms 26040 KB Output is correct
36 Correct 146 ms 29112 KB Output is correct
37 Correct 119 ms 26988 KB Output is correct
38 Correct 107 ms 26944 KB Output is correct
39 Correct 85 ms 25924 KB Output is correct
40 Correct 121 ms 24464 KB Output is correct
41 Correct 178 ms 26064 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 162 ms 26648 KB Output is correct
44 Correct 153 ms 28420 KB Output is correct
45 Correct 149 ms 26284 KB Output is correct
46 Correct 144 ms 30804 KB Output is correct
47 Correct 143 ms 27996 KB Output is correct
48 Correct 124 ms 27852 KB Output is correct
49 Correct 98 ms 26396 KB Output is correct
50 Correct 101 ms 19816 KB Output is correct
51 Correct 146 ms 29248 KB Output is correct
52 Correct 125 ms 25272 KB Output is correct
53 Correct 5 ms 9724 KB Output is correct
54 Correct 5 ms 9728 KB Output is correct
55 Correct 5 ms 9728 KB Output is correct
56 Correct 6 ms 9868 KB Output is correct
57 Correct 6 ms 9868 KB Output is correct
58 Correct 6 ms 9812 KB Output is correct
59 Correct 8 ms 9772 KB Output is correct
60 Correct 6 ms 9812 KB Output is correct
61 Correct 6 ms 9864 KB Output is correct
62 Correct 6 ms 9820 KB Output is correct
63 Correct 8 ms 9816 KB Output is correct
64 Correct 6 ms 9844 KB Output is correct
65 Correct 6 ms 9816 KB Output is correct
66 Correct 6 ms 9784 KB Output is correct
67 Correct 109 ms 27456 KB Output is correct
68 Correct 100 ms 26344 KB Output is correct
69 Correct 134 ms 28820 KB Output is correct
70 Correct 133 ms 28548 KB Output is correct
71 Correct 135 ms 26812 KB Output is correct
72 Correct 126 ms 26676 KB Output is correct
73 Correct 115 ms 30028 KB Output is correct
74 Correct 100 ms 23452 KB Output is correct
75 Correct 113 ms 25712 KB Output is correct
76 Correct 125 ms 24880 KB Output is correct
77 Correct 100 ms 25432 KB Output is correct
78 Correct 103 ms 25328 KB Output is correct
79 Correct 105 ms 27448 KB Output is correct
80 Correct 80 ms 27032 KB Output is correct
81 Correct 151 ms 28032 KB Output is correct
82 Correct 160 ms 28992 KB Output is correct
83 Correct 123 ms 23780 KB Output is correct
84 Correct 98 ms 25664 KB Output is correct
85 Correct 152 ms 30236 KB Output is correct
86 Correct 107 ms 27960 KB Output is correct
87 Correct 107 ms 27912 KB Output is correct
88 Correct 102 ms 23808 KB Output is correct
89 Correct 138 ms 23600 KB Output is correct
90 Correct 167 ms 26052 KB Output is correct
91 Correct 150 ms 28432 KB Output is correct
92 Correct 151 ms 29264 KB Output is correct
93 Correct 157 ms 29976 KB Output is correct
94 Correct 147 ms 27520 KB Output is correct
95 Correct 105 ms 27128 KB Output is correct
96 Correct 103 ms 25992 KB Output is correct
97 Correct 95 ms 19668 KB Output is correct
98 Correct 153 ms 30040 KB Output is correct
99 Correct 114 ms 26064 KB Output is correct
100 Correct 65 ms 14268 KB Output is correct
101 Correct 166 ms 28816 KB Output is correct
102 Correct 128 ms 24756 KB Output is correct
103 Correct 150 ms 21348 KB Output is correct
104 Correct 140 ms 23616 KB Output is correct