일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 자료구조
- 코틀린
- 알고리즘
- 네트워크
- Spring
- 그래프
- baekjoon
- TDD
- programmers
- 운영체제
- 스프링
- backtracking
- DFS
- Brute-force
- 프로젝트
- java
- algorithm
- 백트래킹
- DP
- 백준
- OS
- lambda
- Java8
- BFS
- 프로그래머스
- LEVEL2
- 자바
- kotlin
- back-end
- 모던자바
- Today
- Total
목록알고리즘(Java)/그래프 이론 (7)
요깨비's LAB

import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scr = new Scanner(System.in); int N = scr.nextInt(); Map nodes = new HashMap(); for (int i = 0; i < N; i++) { String id = String.valueOf((char) ('A' + i)); nodes.putIfAbsent(id, new Node(id)); } for (int i = 0; i < N; i++) { String rootId = scr.next(); St..

MST가 최소비용으로 정점을 중복 없이 묶는 것이기 때문에 하나의 최소비용으로 이뤄진 덩어리와 정점 하나짜리 덩어리의 두개의 덩어리로 나누면 자동으로 최소비용으로 두 마을을 구성할 수 있는 아이디어입니다. import java.util.ArrayList; import java.util.List; import java.util.Scanner; class Vertax { Vertax parent; int id; boolean isVisited; public Vertax(int id) { parent = this; this.id = id; this.isVisited = false; } private Vertax findParent(Vertax p) { if (p.id == p.parent.id) { retur..

import java.util.ArrayList; import java.util.List; import java.util.Scanner; class Cow { int id; List preferences; public Cow(int id) { this.id = id; this.preferences = new ArrayList(); } } public class Main { public static int[] barns; public static boolean[] isProccesed; public static List cows; public static int N; public static int M; public static void main(String[] args) { Scanner scr = ne..

import java.util.ArrayList; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; class Vertax { int id; boolean isVisited; List edges; public Vertax(int id) { this.id = id; this.isVisited = false; this.edges = new ArrayList(); } } class Edge { int from; int to; int value; public Edge(int from, int to, int value) { this.from = from; this.to = to; this.value = value; } ..

import java.util.ArrayList; import java.util.List; import java.util.Scanner; class Vertax { Vertax parent; int id; boolean isVisited; public Vertax(int id) { this.id = id; parent = this; isVisited = false; } public Vertax findParent(Vertax v) { if (v.id == v.parent.id) { return v; } return v = findParent(v.parent); } public long merge(Vertax to, long total, int cost) { Vertax from = findParent(p..

이번에는 프림 알고리즘 방식으로 풀었습니다. 이것 또한 정점과 간선을 인스턴스화 하여 풀었습니다. import java.util.*; class Vertax { int id; boolean isVisited; List linkedVertaxes; public Vertax(int id) { this.id = id; this.isVisited = false; this.linkedVertaxes = new ArrayList(); } } class Edge { int toId; int value; public Edge(int toId, int value) { this.toId = toId; this.value = value; } } public class Main { public static void main(..

MST를 이용해서 풀었으며, 기존의 배열을 활용한 풀이보다는 각각의 정점과 간선을 인스턴스화하여 푸는 방식으로 진행하였습니다. import java.util.ArrayList; import java.util.List; import java.util.Scanner; class Vertax { Vertax parent; int id; boolean isVisted; public Vertax(int id, boolean isVisted) { this.parent = this; this.id = id; this.isVisted = isVisted; } public Vertax findParent(Vertax p) { // System.out.println(this.id + ", " + p.id); if(p.id..