File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments