-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
38 lines (37 loc) · 1.04 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace KillProcess
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static IList<int> KillProcess(IList<int> pid, IList<int> ppid, int kill)
{
var graph = new Dictionary<int, List<int>>();
foreach (var process in pid)
graph[process] = new List<int>();
for (int i = 0; i < ppid.Count; i++)
{
if(ppid[i] == 0) continue;
graph[ppid[i]].Add(pid[i]);
}
var res = new List<int>();
var queue = new Queue<int>();
queue.Enqueue(kill);
res.Add(kill);
while (queue.Count != 0)
{
var cur = queue.Dequeue();
foreach (var next in graph[cur])
{
res.Add(next);
queue.Enqueue(next);
}
}
return res;
}
}
}