Submission #311863


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class B2
{
    List<int> remaining;
    List<int>[] children;
    int Solve()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int m = int.Parse(str[1]);

        children = new List<int>[n];
        for (int i = 0; i < n; i++)
            children[i] = new List<int>();

        for (int i = 0; i < m; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]) - 1;
            int y = int.Parse(s[1]) - 1;
            children[x].Add(y);
            children[y].Add(x);
        }

        int need = 0;
        remaining = Enumerable.Range(0, n).ToList();
        while (remaining.Count > 0)
        {
            dfs(remaining.First());
            need++;
        }
        return need - 1;
    }

    void dfs(int node)
    {
        remaining.Remove(node);
        var next = children[node].Intersect(remaining);
        foreach (int index in next)
            dfs(index);
    }

    static void Main(string[] args)
    {
        Console.WriteLine(new B2().Solve());
    }
}

Submission Info

Submission Time
Task B - 道路工事
User paralleltree
Language C# (Mono 2.10.8.1)
Score 0
Code Size 1223 Byte
Status TLE
Exec Time 2063 ms
Memory 301420 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 16
TLE × 4
Set Name Test Cases
Sample sample1.txt, sample2.txt
All 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt
Case Name Status Exec Time Memory
0.txt AC 177 ms 10376 KB
1.txt AC 177 ms 10372 KB
10.txt AC 179 ms 10368 KB
11.txt AC 176 ms 10372 KB
12.txt AC 228 ms 10452 KB
13.txt AC 221 ms 10620 KB
14.txt AC 234 ms 10624 KB
15.txt AC 1188 ms 30284 KB
16.txt TLE 2035 ms 20552 KB
17.txt TLE 2033 ms 20552 KB
18.txt TLE 2034 ms 20520 KB
19.txt TLE 2063 ms 301420 KB
2.txt AC 180 ms 10388 KB
3.txt AC 177 ms 10220 KB
4.txt AC 175 ms 10372 KB
5.txt AC 174 ms 10424 KB
6.txt AC 180 ms 10368 KB
7.txt AC 184 ms 10368 KB
8.txt AC 182 ms 10368 KB
9.txt AC 176 ms 10364 KB
sample1.txt AC 175 ms 10368 KB
sample2.txt AC 181 ms 10408 KB