회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
어디가 틀렸을까요...
9370번 - 미확인 도착지
kchangwook
4년 전
0
아래처럼 작성했는데...
50%에서 자꾸 틀리네요...
어떤 반례가 있을까요?
import java.util.*; public class Main { static int n, m, t, s, g, h; static List<int []> path[]; static List<Integer> list; public static void main(String[] args) { Scanner input = new Scanner(System.in); int testCase = input.nextInt(); for(int abcd = 0; abcd < testCase; abcd++) { n = input.nextInt(); m = input.nextInt(); t = input.nextInt(); s = input.nextInt(); g = input.nextInt(); h = input.nextInt(); int dist[] = new int[n + 1]; path = new ArrayList[n + 1]; list = new ArrayList<>(); Queue<Integer> answer = new PriorityQueue<>(); Queue<int []> que = new PriorityQueue<>((a, b) -> { if(a[1] < b[1]) return -1; else if(a[1] > b[1]) return 1; else return 0; }) ; for(int i = 0; i < m; i++) { int x = input.nextInt(); int y = input.nextInt(); int z = input.nextInt(); if(path[x] == null) path[x] = new ArrayList<>(); if(path[y] == null) path[y] = new ArrayList<>(); int one[] = {y, z}; int two[] = {x, z}; path[x].add(one); path[y].add(two); } for(int i = 0; i < t; i++) list.add(input.nextInt()); Arrays.fill(dist, Integer.MAX_VALUE); dist[s] = 0; int cde[] = {s, 0}; que.add(cde); while(!que.isEmpty()) { int cur[] = que.poll(); int x = cur[0]; int y = cur[1]; if(list.contains(x) && y == 1 && !answer.contains(x)) answer.add(x); for(int i = 0; i < path[x].size(); i++) { int ex[] = path[x].get(i); if(dist[ex[0]] >= dist[x] + ex[1]) { dist[ex[0]] = dist[x] + ex[1]; int temp[] = new int[2]; temp[0] = ex[0]; if((x == g && ex[0] == h) || (x == h && ex[0] == g)) temp[1] = 1; else temp[1] = y; que.add(temp); } } } while(!answer.isEmpty()) { if(answer.size() == 1) System.out.println(answer.poll() + " "); else System.out.print(answer.poll() + " "); } } }// end of main }// end of Main
댓글을 작성하려면
로그인
해야 합니다.
kchangwook 4년 전
아래처럼 작성했는데...
50%에서 자꾸 틀리네요...
어떤 반례가 있을까요?