답안 #1017827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017827 2024-07-09T10:33:04 Z ZeroCool Stranded Far From Home (BOI22_island) C++14
100 / 100
178 ms 16472 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using ll = long long;
using ld = long double;
 
void solve(int T);
void pre();
 
const int N = 2e5 + 10;
const int M = 405;
const int SQRT = 500;
const int LOG = 20;
const int INF = 1e18;
const int MOD = 1e9+7;
const ld EPS = 1e-9;

void pre(){
	#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
	#endif
	
}

int32_t main(){
	pre();
	int tt = 1;
	//cin>>tt;
	for(int i = 1;i<=tt;i++){
		//cerr<<"Case "<<i<<": "<<endl;
		solve(i);
	}
    return 0;
}



struct Edge{
	int u,v,w;
	
};
bool operator<(Edge a,Edge b){
	return a.w < b.w;
}

bool bad[N];

int A[N];
int sum[N];

int p[N];

int find(int u){
	if(p[u] == u)return u;
	int v = find(p[u]);
	bad[u] |= bad[p[u]];
	p[u] = v;
	return v;
}

void join(int u,int v){
	u = find(u);
	v = find(v);

	if(u == v)return;
	if(A[u] < A[v])swap(u,v);
	if(A[u] > sum[v])bad[v] = true;
	p[v] = u;
	sum[u] += sum[v];
}

void solve(int T){
    int n,m;
	cin>>n>>m;
	for(int i = 1;i<=n;i++){
		cin>>A[i];
		p[i] = i;
		sum[i] = A[i];
	}
	Edge edge[m];
	for(int i = 0;i<m;i++){
		int u,v;
		cin>>u>>v;
		edge[i] = {u, v, max(A[u], A[v])}; 
	}
	sort(edge, edge + m);

	for(auto p : edge){
		join(p.u, p.v);
	}
	cerr<<"kur"<<endl;


	for(int i = 1;i<=n;i++){
		find(i);
		cout<<!bad[i];
	}
	cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4552 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 145 ms 14672 KB Output is correct
4 Correct 104 ms 13196 KB Output is correct
5 Correct 174 ms 14060 KB Output is correct
6 Correct 150 ms 14420 KB Output is correct
7 Correct 136 ms 14416 KB Output is correct
8 Correct 133 ms 14368 KB Output is correct
9 Correct 130 ms 14416 KB Output is correct
10 Correct 137 ms 13648 KB Output is correct
11 Correct 111 ms 14904 KB Output is correct
12 Correct 108 ms 13136 KB Output is correct
13 Correct 99 ms 13120 KB Output is correct
14 Correct 109 ms 13264 KB Output is correct
15 Correct 133 ms 14544 KB Output is correct
16 Correct 109 ms 13820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4540 KB Output is correct
2 Correct 158 ms 14508 KB Output is correct
3 Correct 140 ms 14420 KB Output is correct
4 Correct 132 ms 14448 KB Output is correct
5 Correct 101 ms 12884 KB Output is correct
6 Correct 160 ms 14416 KB Output is correct
7 Correct 144 ms 14480 KB Output is correct
8 Correct 139 ms 14592 KB Output is correct
9 Correct 142 ms 13660 KB Output is correct
10 Correct 126 ms 13760 KB Output is correct
11 Correct 110 ms 13048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 160 ms 14408 KB Output is correct
3 Correct 162 ms 14404 KB Output is correct
4 Correct 143 ms 14440 KB Output is correct
5 Correct 142 ms 14532 KB Output is correct
6 Correct 137 ms 14156 KB Output is correct
7 Correct 133 ms 16464 KB Output is correct
8 Correct 116 ms 13400 KB Output is correct
9 Correct 90 ms 12116 KB Output is correct
10 Correct 102 ms 12992 KB Output is correct
11 Correct 102 ms 13116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4552 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 145 ms 14672 KB Output is correct
18 Correct 104 ms 13196 KB Output is correct
19 Correct 174 ms 14060 KB Output is correct
20 Correct 150 ms 14420 KB Output is correct
21 Correct 136 ms 14416 KB Output is correct
22 Correct 133 ms 14368 KB Output is correct
23 Correct 130 ms 14416 KB Output is correct
24 Correct 137 ms 13648 KB Output is correct
25 Correct 111 ms 14904 KB Output is correct
26 Correct 108 ms 13136 KB Output is correct
27 Correct 99 ms 13120 KB Output is correct
28 Correct 109 ms 13264 KB Output is correct
29 Correct 133 ms 14544 KB Output is correct
30 Correct 109 ms 13820 KB Output is correct
31 Correct 1 ms 4540 KB Output is correct
32 Correct 158 ms 14508 KB Output is correct
33 Correct 140 ms 14420 KB Output is correct
34 Correct 132 ms 14448 KB Output is correct
35 Correct 101 ms 12884 KB Output is correct
36 Correct 160 ms 14416 KB Output is correct
37 Correct 144 ms 14480 KB Output is correct
38 Correct 139 ms 14592 KB Output is correct
39 Correct 142 ms 13660 KB Output is correct
40 Correct 126 ms 13760 KB Output is correct
41 Correct 110 ms 13048 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 160 ms 14408 KB Output is correct
44 Correct 162 ms 14404 KB Output is correct
45 Correct 143 ms 14440 KB Output is correct
46 Correct 142 ms 14532 KB Output is correct
47 Correct 137 ms 14156 KB Output is correct
48 Correct 133 ms 16464 KB Output is correct
49 Correct 116 ms 13400 KB Output is correct
50 Correct 90 ms 12116 KB Output is correct
51 Correct 102 ms 12992 KB Output is correct
52 Correct 102 ms 13116 KB Output is correct
53 Correct 1 ms 4440 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 2 ms 4444 KB Output is correct
57 Correct 2 ms 4444 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 2 ms 4444 KB Output is correct
60 Correct 2 ms 4440 KB Output is correct
61 Correct 2 ms 4444 KB Output is correct
62 Correct 2 ms 4444 KB Output is correct
63 Correct 3 ms 4600 KB Output is correct
64 Correct 2 ms 4444 KB Output is correct
65 Correct 1 ms 4444 KB Output is correct
66 Correct 2 ms 4440 KB Output is correct
67 Correct 133 ms 14412 KB Output is correct
68 Correct 104 ms 13244 KB Output is correct
69 Correct 142 ms 14204 KB Output is correct
70 Correct 138 ms 14504 KB Output is correct
71 Correct 136 ms 14524 KB Output is correct
72 Correct 168 ms 14524 KB Output is correct
73 Correct 137 ms 14420 KB Output is correct
74 Correct 151 ms 13760 KB Output is correct
75 Correct 111 ms 14928 KB Output is correct
76 Correct 105 ms 13132 KB Output is correct
77 Correct 97 ms 12988 KB Output is correct
78 Correct 107 ms 13136 KB Output is correct
79 Correct 133 ms 14416 KB Output is correct
80 Correct 110 ms 13836 KB Output is correct
81 Correct 178 ms 14416 KB Output is correct
82 Correct 148 ms 14528 KB Output is correct
83 Correct 146 ms 14668 KB Output is correct
84 Correct 100 ms 12884 KB Output is correct
85 Correct 138 ms 14420 KB Output is correct
86 Correct 142 ms 14444 KB Output is correct
87 Correct 134 ms 14672 KB Output is correct
88 Correct 113 ms 13900 KB Output is correct
89 Correct 106 ms 12988 KB Output is correct
90 Correct 143 ms 14424 KB Output is correct
91 Correct 138 ms 14420 KB Output is correct
92 Correct 134 ms 14420 KB Output is correct
93 Correct 155 ms 14412 KB Output is correct
94 Correct 134 ms 14156 KB Output is correct
95 Correct 124 ms 16472 KB Output is correct
96 Correct 110 ms 13392 KB Output is correct
97 Correct 101 ms 12184 KB Output is correct
98 Correct 113 ms 12884 KB Output is correct
99 Correct 106 ms 13136 KB Output is correct
100 Correct 67 ms 11092 KB Output is correct
101 Correct 158 ms 14420 KB Output is correct
102 Correct 141 ms 13512 KB Output is correct
103 Correct 148 ms 13780 KB Output is correct
104 Correct 154 ms 14372 KB Output is correct