Skip to content

Commit 1f48344

Browse files
committed
[Silver II] Title: 친구, Time: 156 ms, Memory: 17756 KB -BaekjoonHub
1 parent 4ed1979 commit 1f48344

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Silver II] 친구 - 1058
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1058)
4+
5+
### 성능 요약
6+
7+
메모리: 17756 KB, 시간: 156 ms
8+
9+
### 분류
10+
11+
그래프 이론, 브루트포스 알고리즘, 그래프 탐색, 최단 경로, 플로이드–워셜
12+
13+
### 제출 일자
14+
15+
2026년 1월 28일 12:35:59
16+
17+
### 문제 설명
18+
19+
<p>지민이는 세계에서 가장 유명한 사람이 누구인지 궁금해졌다. 가장 유명한 사람을 구하는 방법은 각 사람의 2-친구를 구하면 된다. 어떤 사람 A가 또다른 사람 B의 2-친구가 되기 위해선, 두 사람이 친구이거나, A와 친구이고, B와 친구인 C가 존재해야 된다. 여기서 가장 유명한 사람은 2-친구의 수가 가장 많은 사람이다. 가장 유명한 사람의 2-친구의 수를 출력하는 프로그램을 작성하시오.</p>
20+
21+
<p>A와 B가 친구면, B와 A도 친구이고, A와 A는 친구가 아니다.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 사람의 수 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 각 사람이 친구이면 Y, 아니면 N이 주어진다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 가장 유명한 사람의 2-친구의 수를 출력한다.</p>
30+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int n;
6+
static char[][] map;
7+
static int answer = Integer.MIN_VALUE;
8+
9+
public static void main(String[] args) throws IOException {
10+
Scanner sc = new Scanner(System.in);
11+
n = sc.nextInt();
12+
map = new char[n][n];
13+
for (int i = 0; i < n; i++) {
14+
String s = sc.next();
15+
for (int j = 0; j < n; j++) {
16+
map[i][j] = s.charAt(j);
17+
}
18+
}
19+
20+
solve();
21+
22+
}
23+
24+
public static void solve() {
25+
26+
for (int i = 0; i < n; i++) {
27+
int count = 0;
28+
boolean[] check = new boolean[n];
29+
check[i] = true;
30+
for (int f = 0; f < n; f++) {
31+
if (map[i][f] == 'N')
32+
continue;
33+
check[f] = true;
34+
count++;
35+
}
36+
37+
for (int j = 0; j < n; j++) {
38+
if (map[i][j] == 'N')
39+
continue;
40+
for (int ff = 0; ff < n; ff++) {
41+
if (check[ff])
42+
continue;
43+
if (map[j][ff] == 'N')
44+
continue;
45+
check[ff] = true;
46+
count++;
47+
}
48+
}
49+
answer = Math.max(answer, count);
50+
}
51+
System.out.println(answer);
52+
}
53+
54+
}

0 commit comments

Comments
 (0)