이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.*;
public class mor {
static ArrayList<Integer>[] adj;
public static void main(String[] args) throws IOException, FileNotFoundException {
// Scanner in = new Scanner(new File("seafaring.in"));
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int M = in.nextInt();
int K = in.nextInt();
adj = new ArrayList[N];
for(int i = 0; i < N; i++){
adj[i] = new ArrayList<>();
}
int[][][] dp = new int[N][N][2];
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
Arrays.fill(dp[i][j], 1000000);
}
}
for(int i = 0; i < M; i++){
int a = in.nextInt() - 1;
int b = in.nextInt() - 1;
dp[a][a][0] = 0;
dp[b][b][0] = 0;
adj[a].add(b);
adj[b].add(a);
}
// check what the minimum odd path is and the minimum even path is
boolean[][][] visited = new boolean[N][N][2];
for(int i = 0; i < N; i++){
PriorityQueue<State> pq = new PriorityQueue<>();
pq.add(new State(i, 0));
while(!pq.isEmpty()){
State curr = pq.poll();
if(dp[i][curr.position][curr.distance % 2] != curr.distance){
continue;
}
for(int ap: adj[curr.position]){
if(curr.distance + 1 < dp[i][ap][(curr.distance + 1)%2]){
dp[i][ap][(curr.distance + 1)%2] = Math.min(dp[i][ap][(curr.distance + 1) % 2], curr.distance + 1);
pq.add(new State(ap, curr.distance + 1));
}
}
}
}
// for(int i = 0; i < N; i++){
// System.out.println("i: " + i);
// for(int j = 0; j < N; j++){
// System.out.println(" j: " + j);
// System.out.println(" " + Arrays.toString(dp[i][j]));
// }
// }
for(int i = 0; i < K; i++){
int start = in.nextInt() - 1;
int end = in.nextInt() - 1;
int dist = in.nextInt();
// System.out.println(Arrays.toString(distances[start][end]));
if(dp[start][end][dist % 2] <= dist && dp[start][end][dist % 2] != 1000000){
System.out.println("TAK");
} else {
System.out.println("NIE");
}
}
}
public static class State implements Comparable<State>{
int position;
int distance;
public State(int position, int distance){
this.position = position;
this.distance = distance;
}
public int compareTo(State s){
return distance - s.distance;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
Note: mor.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |