Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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๋กœ ๊ทธ๋ž˜ํ”„ ๊ตฌํ˜„(์ž๋ฐ”) ๋ณธ๋ฌธ

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

์ธ์ ‘ array๋กœ ๊ทธ๋ž˜ํ”„ ๊ตฌํ˜„(์ž๋ฐ”)

JihyunLee 2019. 4. 2. 08:52
๋ฐ˜์‘ํ˜•
package ch6;
//array ๋กœ graph ๊ตฌํ˜„ 
/*
 * ์˜ˆ์ œ์ž…๋ ฅ 
 * 4 5 1	์ •์ ์˜์ˆ˜, ๊ฐ„์„ ์˜์ˆ˜, ํƒ์ƒ‰์„ ์‹œ์ž‘ํ•  ๋ฒˆ
	1 2
	1 3
	1 4
	2 4
	3 4
 */
import java.util.*;
public class graph_array {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();// node์˜ ์ˆ˜ 
		int[][] a = new int[n+1][n+1];
		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][w] = a[w][v] = 1;
		}
		//์ธ์ ‘์–ด๋ ˆ์ด  ํ™•์ธ  
		for(int i=1; i<n+1; i++) {
			for(int j=1; j<n+1; j++) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println("");
		}
		
		
 		
	}
}

 

๋ฐ˜์‘ํ˜•