Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- DP - 무한배낭(순서)
- Union-Find
- qfieldname
- NEW-PAGE PRINT ON
- boole_d
- transporting
- Data Browser
- MONAT_F4
- BOJ_Gold
- APPENDING CORRESPONDING
- using value
- changing value
- batch job
- 필드카탈로그
- DP - 유한배낭
- 날짜 계산 함수
- ZPL
- Dictionary Search Help
- DP - 무한배낭
- SAP GUI
- APPENDING
- ABAP
- ALV Output Setting
- CTS #CTS 이관 #SAP #ABAP
- READ TABLE
- FOR ALL ENTRIES IN
- SM36
- cfieldname
- SAP
- java
Archives
- Today
- Total
Jin's Library
[Gold Ⅱ] 10775 - 공항 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BOJ_10775 {
static int[] parent;
static int find(int x){
if(parent[x] == x) return x;
return parent[x] = find(parent[x]);
}
static void union(int a, int b){
a = find(a);
b = find(b);
if(a != b) parent[b] = a;
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine()); // 게이트의 수
int M = Integer.parseInt(br.readLine()); // 비행기의 수
int P = 0, D = 0, f = 0;
boolean flag = false;
parent = new int[N+1];
for(int i = 0; i <= N; i++) parent[i] = i;
for(int i = 0; i < M; i++){
P = Integer.parseInt(br.readLine());
if(flag) continue;
f = find(P);
if(f > 0){
union(f-1, f);
D++;
}else flag = true;
}
System.out.println(D);
}
}'Algorithm - Java > BOJ - Gold' 카테고리의 다른 글
| [Gold Ⅴ] 1931 - 회의실 배정 (0) | 2025.10.17 |
|---|---|
| [Gold Ⅳ] 1043 - 거짓말 (0) | 2025.10.02 |
| [Gold Ⅴ] 1717 - 집합의 표현 (0) | 2025.10.01 |
| [Gold Ⅳ] 1976 - 여행 가자 (0) | 2025.10.01 |
| [Gold Ⅳ] 17298 - 오큰수 (0) | 2025.09.30 |