회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
시간초과가 왜 날까요??ㅜㅜ
1005번 - ACM Craft
yb3231
7년 전
0
시간초과가 나네요~
작성된 코드에서 무엇이 문제일까요?
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; public class Main { // 변경된값 static int[] loc; // 초기값 static int[] ori; static class Node{ // 번호 int order; Set<Node> list = new HashSet<>(); } private static int searchNod(Node node){ if(node.list== null || node.list.isEmpty()){ return loc[node.order]; } int max = 0; for(Node subNode : node.list){ int order = node.order; int suborder = subNode.order; // if( (ori[suborder] + loc[order]) > loc[suborder]){ loc[suborder] = ori[suborder] + loc[order]; max = Math.max(max, searchNod(subNode)); } } return max; } public static void main(String args[]) throws Exception { List<Integer> list = new ArrayList<>(); Scanner sc = new Scanner(System.in); int cnt = sc.nextInt(); for(int i = 0; i < cnt ; i++){ int n, k; n = sc.nextInt(); k = sc.nextInt(); Node[] nodes = new Node[n]; loc = new int[n]; ori = new int[n]; for(int j = 0; j < n ; j++){ int t = sc.nextInt(); nodes[j] = new Node(); nodes[j].order = j; ori[j] = t; loc[j] = t; } for(int j = 0; j < k ; j++){ int first = sc.nextInt() -1; int second = sc.nextInt() -1; nodes[second].list.add(nodes[first]); } System.out.println(searchNod(nodes[val-1])); } sc.close(); } }
nisroeld99
7년 전
0
queue 이용한 테크트리 문제입니다
댓글을 작성하려면
로그인
해야 합니다.
yb3231 7년 전
시간초과가 나네요~
작성된 코드에서 무엇이 문제일까요?