Submission #1241331
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; } System.out.println(pass_list.size()); 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 | 1776 Byte |
Status | TLE |
Exec Time | 2105 ms |
Memory | 104208 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 | AC | 95 ms | 21588 KB |
sample_02.txt | AC | 94 ms | 18900 KB |
sample_03.txt | AC | 95 ms | 21844 KB |
subtask_1_01.txt | AC | 554 ms | 79184 KB |
subtask_1_02.txt | AC | 456 ms | 46740 KB |
subtask_1_03.txt | AC | 624 ms | 73092 KB |
subtask_1_04.txt | AC | 586 ms | 85440 KB |
subtask_1_05.txt | AC | 596 ms | 88944 KB |
subtask_1_06.txt | AC | 611 ms | 86860 KB |
subtask_1_07.txt | AC | 612 ms | 103988 KB |
subtask_1_08.txt | AC | 589 ms | 97360 KB |
subtask_1_09.txt | TLE | 2105 ms | 104208 KB |
subtask_1_10.txt | AC | 425 ms | 48188 KB |
subtask_1_11.txt | AC | 457 ms | 49140 KB |
subtask_1_12.txt | AC | 95 ms | 21588 KB |
subtask_1_13.txt | AC | 96 ms | 21332 KB |