Submission #1334717


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);
        int S = -1, minDeg = int.MaxValue;
        for (int i = 0; i < N; i++)
            if (E[i].Length > 0 && CheckMin(ref minDeg, E[i].Length)) S = i;
        var adj = new bool[N];
        foreach (int v in E[S]) adj[v] = true;
        var ans = new List<int>();
        var seen = new bool[N];
        int count = 0;
        for (int at = S; count != E[S].Length; )
        {
            ans.Add(at);
            seen[at] = true;
            if (adj[at]) count++;
            foreach (int next in E[at])
                if (!seen[next])
                {
                    at = next;
                    break;
                }
        }

        Console.WriteLine(ans.Count + "\n" + string.Join(" ", ans.Select(v => v + 1)));
    }

    bool CheckMin(ref int a, int b) { if (b < a) { a = b; return true; } return false; }

    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() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    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; }
    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 0
Code Size 3429 Byte
Status WA
Exec Time 2112 ms
Memory 1148660 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 2
AC × 5
WA × 12
TLE × 2
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 27 ms 11476 KB
sample_02.txt WA 27 ms 11476 KB
sample_03.txt WA 27 ms 11476 KB
subtask_1_01.txt WA 142 ms 24152 KB
subtask_1_02.txt TLE 2109 ms 807424 KB
subtask_1_03.txt WA 132 ms 22152 KB
subtask_1_04.txt WA 156 ms 20904 KB
subtask_1_05.txt WA 148 ms 22824 KB
subtask_1_06.txt TLE 2112 ms 1148660 KB
subtask_1_07.txt WA 183 ms 30856 KB
subtask_1_08.txt WA 170 ms 32268 KB
subtask_1_09.txt WA 168 ms 28044 KB
subtask_1_10.txt AC 84 ms 18124 KB
subtask_1_11.txt AC 74 ms 14792 KB
subtask_1_12.txt AC 27 ms 11476 KB
subtask_1_13.txt WA 28 ms 13524 KB