Submission #1356927
Source Code Expand
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int N = Reader.Int(), M = Reader.Int(); var E = EdgeRead(N, M); var seen = new bool[N]; Func<int, List<int>> Gen = (start) => { var res = new List<int>(); for (int a = start; a != -1 && !seen[a]; ) { seen[a] = true; res.Add(a + 1); a = Array.Find(E[a], i => !seen[i]); } return res; }; seen[0] = true; var R = Gen(E[0][0]); seen[0] = false; var L = Gen(0); var ans = L.Reverse<int>().Concat(R); Console.WriteLine(ans.Count() + "\n" + string.Join(" ", ans)); } int[][] EdgeRead(int V, int E = -1, int origin = 1) { if (E == -1) E = V - 1; var es = new List<int>[V]; for (int i = 0; i < V; i++) es[i] = new List<int>(); for (int i = 0; i < E; i++) { int a = Reader.Int() - origin, b = Reader.Int() - origin; es[a].Add(b); es[b].Add(a); } return es.Select(a => a.ToArray()).ToArray(); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { Dispose(); A = new string[0]; } public static void Set(TextReader r) { Init(); reader = r; } public static void Set(string file) { Init(); reader = new StreamReader(file); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } public static void Dispose() { reader.Dispose(); } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | eitaho |
Language | C# (Mono 4.6.2.0) |
Score | 500 |
Code Size | 3251 Byte |
Status | AC |
Exec Time | 219 ms |
Memory | 37600 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 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 | 30 ms | 13652 KB |
sample_02.txt | AC | 29 ms | 11604 KB |
sample_03.txt | AC | 29 ms | 13652 KB |
subtask_1_01.txt | AC | 150 ms | 24152 KB |
subtask_1_02.txt | AC | 58 ms | 20444 KB |
subtask_1_03.txt | AC | 142 ms | 25220 KB |
subtask_1_04.txt | AC | 152 ms | 22824 KB |
subtask_1_05.txt | AC | 160 ms | 22824 KB |
subtask_1_06.txt | AC | 151 ms | 22824 KB |
subtask_1_07.txt | AC | 184 ms | 33592 KB |
subtask_1_08.txt | AC | 172 ms | 28040 KB |
subtask_1_09.txt | AC | 219 ms | 37600 KB |
subtask_1_10.txt | AC | 69 ms | 16204 KB |
subtask_1_11.txt | AC | 78 ms | 16968 KB |
subtask_1_12.txt | AC | 28 ms | 11604 KB |
subtask_1_13.txt | AC | 29 ms | 13524 KB |