diff --git a/khj20006/202502/04 BOJ A Journey to Greece.md b/khj20006/202502/04 BOJ A Journey to Greece.md new file mode 100644 index 00000000..82bebda8 --- /dev/null +++ b/khj20006/202502/04 BOJ A Journey to Greece.md @@ -0,0 +1,132 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static int INF = (int)1e9 + 1; + static int N, P, M, G, T; + static int[] p; + static int[] num; + static List[] V; + static int[][] dist; + static int[][] cost; + static int[][][] dp; + + static void sizeInitialize() { + p = new int[P+1]; + num = new int[N+1]; + V = new ArrayList[N+1]; + for(int i=0;i<=N;i++) V[i] = new ArrayList<>(); + dist = new int[P+1][N+1]; + cost = new int[P+1][P+1]; + dp = new int[P+1][2][1<<(P+1)]; + for(int i=0;i<=P;i++) for(int j=0;j<2;j++) Arrays.fill(dp[i][j], INF); + } + + static void input() throws Exception { + + nextLine(); + N = nextInt(); + P = nextInt(); + M = nextInt(); + G = nextInt(); + T = nextInt(); + + sizeInitialize(); + + for(int i=1;i<=P;i++) { + nextLine(); + int a = nextInt(), b = nextInt(); + G -= b; + p[i] = a; + num[p[i]] = i; + } + + for(int i=0;i PQ = new PriorityQueue<>((a,b) -> a[0]-b[0]); + PQ.offer(new int[] {0,p[s]}); + dist[s][p[s]] = 0; + while(!PQ.isEmpty()) { + int[] now = PQ.poll(); + int d = now[0], n = now[1]; + if(d > dist[s][n]) continue; + for(int[] x : V[n]) { + int nx = x[0], c = x[1]; + if(dist[s][nx] > d + c) { + dist[s][nx] = d+c; + PQ.offer(new int[] {d+c,nx}); + } + } + } + + } + + static void constructNewGraph() { + for(int i=0;i<=P;i++) for(int j=0;j<=P;j++) cost[i][j] = dist[i][p[j]]; + } + + static int solve(int n, int x, int k) { + if(dp[n][x][k] != INF) return dp[n][x][k]; + int prev = k ^ (1<