Submission #311071
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.Text; class B1 { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int[] a = new int[m]; int[] b = new int[m]; for (int i = 0; i < m; i++) { string[] s = Console.ReadLine().Split(' '); a[i] = int.Parse(s[0]) - 1; b[i] = int.Parse(s[1]) - 1; } int need = 0; var searched = new List<int>(n); while (searched.Count < n) { int start = Enumerable.Range(0, n).Except(searched).First(); var queue = new Queue<int>(n); queue.Enqueue(start); while (queue.Count > 0) { int node = queue.Dequeue(); searched.Add(node); var next = IndexOf(a, node).Select(i => b[i]).Except(searched).Except(queue) .Concat(IndexOf(b, node).Select(i => a[i]).Except(searched).Except(queue)) .Distinct(); foreach (int index in next) { queue.Enqueue(index); } } need++; } Console.WriteLine(need - 1); Console.ReadLine(); } static IEnumerable<int> IndexOf(int[] array, int target) { for (int i = 0; i < array.Length; i++) if (array[i] == target) yield return i; } }
Submission Info
Submission Time | |
---|---|
Task | B - 道路工事 |
User | paralleltree |
Language | C# (Mono 2.10.8.1) |
Score | 0 |
Code Size | 1590 Byte |
Status | TLE |
Exec Time | 2037 ms |
Memory | 13240 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||
Status |
|
|
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 | 142 ms | 10368 KB |
1.txt | AC | 144 ms | 10528 KB |
10.txt | AC | 147 ms | 10440 KB |
11.txt | AC | 145 ms | 10428 KB |
12.txt | AC | 358 ms | 11040 KB |
13.txt | AC | 354 ms | 11064 KB |
14.txt | AC | 353 ms | 11160 KB |
15.txt | AC | 1604 ms | 12072 KB |
16.txt | TLE | 2036 ms | 13196 KB |
17.txt | TLE | 2035 ms | 13240 KB |
18.txt | TLE | 2036 ms | 13192 KB |
19.txt | TLE | 2037 ms | 13064 KB |
2.txt | AC | 144 ms | 10452 KB |
3.txt | AC | 144 ms | 10448 KB |
4.txt | AC | 146 ms | 10440 KB |
5.txt | AC | 147 ms | 10428 KB |
6.txt | AC | 146 ms | 10404 KB |
7.txt | AC | 148 ms | 10428 KB |
8.txt | AC | 166 ms | 10440 KB |
9.txt | AC | 148 ms | 10408 KB |
sample1.txt | AC | 148 ms | 10388 KB |
sample2.txt | AC | 148 ms | 10440 KB |