Skip to content

Commit 69525ec

Browse files
authored
Merge pull request #652 from AlgorithmWithGod/suyeun84
[20250812] BOJ / G5 / 세 친구 / 김수연
2 parents 2835b11 + c8a9f81 commit 69525ec

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj17089 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int M = nextInt();
15+
boolean[][] friend = new boolean[N+1][N+1];
16+
int[] count = new int[N+1];
17+
for (int i = 0; i < M; i++) {
18+
nextLine();
19+
int a = nextInt();
20+
int b = nextInt();
21+
friend[a][b] = true;
22+
friend[b][a] = true;
23+
count[a]++;
24+
count[b]++;
25+
}
26+
27+
int min = Integer.MAX_VALUE;
28+
29+
for(int A = 1; A < N+1; A++) {
30+
for(int B = A+1; B < N+1; B++) {
31+
if(!friend[A][B]) continue;
32+
for(int C = B+1; C < N+1; C++) {
33+
if(!friend[C][A] || !friend[C][B]) continue;
34+
35+
int sum = count[A] + count[B] + count[C] - 6;
36+
min = Math.min(min, sum);
37+
}
38+
}
39+
}
40+
41+
if(min == Integer.MAX_VALUE) System.out.println(-1);
42+
else System.out.println(min);
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)