-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEIMKF.cs
74 lines (63 loc) · 1.82 KB
/
EIMKF.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DFS_Undirected
{
class Program
{
static List<int>[] graph;
static void Main(string[] args)
{
int n = NextInt();
int m = NextInt();
graph = new List<int>[n];
for (int i = 0; i < n; i++)
{
graph[i] = new List<int>();
}
for (int i = 0; i < m; i++)
{
int u = NextInt();
int v = NextInt();
graph[u].Add(v);
graph[v].Add(u);
}
for (int i = 0; i < n; i++)
{
graph[i].Sort();
}
StringBuilder result = new StringBuilder();
for (int i = 0; i < n; i++)
{
result.Append(i +" " +graph[i].Count+" ");
foreach (var node in graph[i])
{
result.Append(node+" ");
}
result.Append("\n");
}
Console.WriteLine(result);
}
static int s_index = 0; static List<string> s_tokens;
private static string Next()
{
while (s_tokens == null || s_index == s_tokens.Count)
{
s_tokens = Console.ReadLine().Split(' ').ToList();
s_index = 0;
}
return s_tokens[s_index++];
}
private static int NextInt()
{
return Int32.Parse(Next());
}
private static long NextLong()
{
return Int64.Parse(Next());
}
}
}