Submission #1241314
Source Code Expand
import java.util.ArrayList; import java.util.Scanner; public class Main { static class Node{ private ArrayList<Integer>next_list; public Node(){ next_list = new ArrayList<>(); } public void addNext(int next){ next_list.add(next); } public int getNextCount(){ return next_list.size(); } public int getNextId(int id){ return next_list.get(id); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int node_count = sc.nextInt(); int pass_count = sc.nextInt(); Node[] node_list = new Node[node_count]; for(int i = 0;i < node_list.length;i++){ node_list[i] = new Node(); } for(int i = 0;i < pass_count;i++){ int j = sc.nextInt() - 1; int k = sc.nextInt() - 1; node_list[j].addNext(k); node_list[k].addNext(j); } ArrayList<Integer>pass_list = new ArrayList<Integer>(); pass_list.add(0); while(true){ Node front_node = node_list[pass_list.get(0)]; int i = 0; for(i = 0;i < front_node.getNextCount();i++){ int j = front_node.getNextId(i); if(!pass_list.contains(j)){ pass_list.add(0, j); break; } } if(i != front_node.getNextCount())continue; Node back_node = node_list[pass_list.get(pass_list.size() - 1)]; for(i = 0;i < back_node.getNextCount();i++){ int j = back_node.getNextId(i); if(!pass_list.contains(j)){ pass_list.add(j); break; } } if(i == back_node.getNextCount())break; } for(int i = 0;i < pass_list.size();i++){ System.out.print(pass_list.get(i) + 1); if(i != pass_list.size() - 1)System.out.print(" "); } System.out.println(); sc.close(); } }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | aetenotanaka |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 1735 Byte |
Status | WA |
Exec Time | 2105 ms |
Memory | 105068 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | WA | 93 ms | 21204 KB |
sample_02.txt | WA | 92 ms | 19924 KB |
sample_03.txt | WA | 94 ms | 20564 KB |
subtask_1_01.txt | WA | 569 ms | 80460 KB |
subtask_1_02.txt | WA | 410 ms | 41088 KB |
subtask_1_03.txt | WA | 608 ms | 74228 KB |
subtask_1_04.txt | WA | 587 ms | 95480 KB |
subtask_1_05.txt | WA | 597 ms | 94740 KB |
subtask_1_06.txt | WA | 629 ms | 87808 KB |
subtask_1_07.txt | WA | 575 ms | 94540 KB |
subtask_1_08.txt | WA | 625 ms | 105068 KB |
subtask_1_09.txt | TLE | 2105 ms | 103708 KB |
subtask_1_10.txt | WA | 414 ms | 47976 KB |
subtask_1_11.txt | WA | 457 ms | 61120 KB |
subtask_1_12.txt | WA | 92 ms | 18772 KB |
subtask_1_13.txt | WA | 98 ms | 18640 KB |