회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
도저히 모르겠습니다...
1707번 - 이분 그래프
dlcksdnd321
4년 전
0
반례도 다맞는데 어디서 틀린건가요 ??
package AlgoStudy; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class B1707 { static int[] visit; // {0 : 방문안함 , 1: red, 2: black} static ArrayList<Integer>[] graph; static Queue<Integer> pqueue; public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(bf.readLine()); int testCase = Integer.parseInt(st.nextToken()); while (testCase-- > 0) { st = new StringTokenizer(bf.readLine()); int N = Integer.parseInt(st.nextToken()); visit = new int[N + 1]; int M = Integer.parseInt(st.nextToken()); graph = new ArrayList[N + 1]; for (int i = 0; i < graph.length; i++) { graph[i] = new ArrayList<Integer>(); } for (int i = 0; i < M; i++) { st = new StringTokenizer(bf.readLine()); int start = Integer.parseInt(st.nextToken()); int end = Integer.parseInt(st.nextToken()); graph[start].add(end); graph[end].add(start); } // arraylist 형식의 그래프 완성이다 boolean yes = true; for (int start = 1; start <= N; start++) { pqueue = new LinkedList(); if(visit[start] != 0) continue; pqueue.add(start); visit[start] = 1; yes = true; while (!pqueue.isEmpty()) { int node = pqueue.poll(); int nowColor = visit[node]; for (int i = 0; i < graph[node].size(); i++) { int friend = graph[node].get(i); if (visit[friend] == nowColor) { System.out.print("NO"); yes = false; start = N+1; graph[node].clear(); pqueue.clear(); } } for (int i = 0; i < graph[node].size(); i++) { int friend = graph[node].get(i); if (visit[friend] == 0) { pqueue.add(friend); visit[friend] = nowColor == 1 ? 2 : 1; } } } } if (yes) { System.out.print("YES"); } } } }
lovinix
4년 전
0
일단 이 코드는 패키지와 클래스명으로 인하여 컴파일 에러를 받겠네요
댓글을 작성하려면
로그인
해야 합니다.
dlcksdnd321 4년 전
반례도 다맞는데 어디서 틀린건가요 ??