Notice
Recent Posts
Recent Comments
ยซ   2024/09   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Tags more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐ŸŒฒ์ž๋ผ๋‚˜๋Š”์ฒญ๋…„

array list๋กœ ๊ตฌํ˜„ํ•œ graph ๋ณธ๋ฌธ

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด

array list๋กœ ๊ตฌํ˜„ํ•œ graph

JihyunLee 2019. 4. 2. 09:08
๋ฐ˜์‘ํ˜•
package ch6;
import java.util.*;
//list ๋กœ graph ๊ตฌํ˜„ 
/*
* ์˜ˆ์ œ์ž…๋ ฅ 
* 4 5 1	์ •์ ์˜์ˆ˜, ๊ฐ„์„ ์˜์ˆ˜, ํƒ์ƒ‰์„ ์‹œ์ž‘ํ• ๋ฒˆํ˜ธ 
	1 2
	1 3
	1 4
	2 4
	3 4
*/

public class graph_list {
	public static void Main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n= scan.nextInt();
		ArrayList<Integer>[] a = (ArrayList<Integer>[]) new ArrayList[n+1];
		for(int i=1;i<n+1;i++) {
			a[i] = new ArrayList<>();
		}
		int num = scan.nextInt();
		int start = scan.nextInt();
		
		for(int i=0;i<num; i++) {
			int v=scan.nextInt();
			int w=scan.nextInt();
			a[v].add(w);
			a[w].add(v);
			
		}
		
	
		
	}

}
๋ฐ˜์‘ํ˜•