File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 11package com .leetcode ;
22
3+ import java .util .Scanner ;
4+
35public class BingChaJi {
46 public int [] father = new int [1000 ];
57 public int [] rank = new int [1000 ];
@@ -24,4 +26,27 @@ public void merge(int i, int j) {
2426 rank [y ]++;
2527 }
2628 }
29+ public static void main (String [] args ) {
30+ Scanner sc = new Scanner (System .in );
31+ int n = sc .nextInt ();
32+ int m = sc .nextInt ();
33+ int p = sc .nextInt ();
34+ BingChaJi bingChaJi = new BingChaJi ();
35+ bingChaJi .init (n );
36+ for (int i = 0 ; i < m ; i ++) {
37+ int x = sc .nextInt ();
38+ int y = sc .nextInt ();
39+ bingChaJi .merge (x , y );
40+ }
41+ for (int i = 0 ; i < p ; i ++) {
42+ int x = sc .nextInt ();
43+ int y = sc .nextInt ();
44+ if (bingChaJi .find (x ) == bingChaJi .find (y )) {
45+ System .out .println ("YES" );
46+ }
47+ else {
48+ System .out .println ("NO" );
49+ }
50+ }
51+ }
2752}
You can’t perform that action at this time.
0 commit comments