fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using Debug = System.Diagnostics.Debug;
  6. using StringBuilder = System.Text.StringBuilder;
  7. public class SuccessfulMerger
  8. {
  9. public int minimumMergers(int[] road)
  10. {
  11. var n = road.Length;
  12. var G = Enumerate(n, x => new List<int>());
  13. for (int i = 0; i < n; i++)
  14. {
  15. G[i].Add(road[i]);
  16. G[road[i]].Add(i);
  17. }
  18. var isCycle = new bool[n];
  19.  
  20. //閉路検出
  21. {
  22. for (int i = 0; i < n; i++)
  23. isCycle[i] = true;
  24. var notCycle = Graph.TopologicalSort(G);
  25. foreach (var x in notCycle)
  26. isCycle[x] = false;
  27. }
  28. }
  29. static public T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
  30. }
  31.  
  32. #region TopologicalSort
  33. static partial class Graph
  34. {
  35. //順序をいじりたい場合はQueueから変える
  36. //使わない奴がある場合はcountのその位置に予め-1を入れて渡す
  37. //循環してるとサイズが小さくなるはず?
  38. static public int[] TopologicalSort(List<int>[] G, int[] count = null)
  39. {
  40. const int Capacity = 1;//有向ならば0無向ならば1
  41. var n = G.Length;
  42. if (count == null)
  43. {
  44. count = new int[n];
  45. foreach (var l in G)
  46. foreach (var x in l) count[x]++;
  47. }
  48. var ret = new List<int>();
  49. var q = new Queue<int>();
  50. for (int i = 0; i < n; i++)
  51. if (count[i] == Capacity) q.Enqueue(i);
  52. while (q.Any())
  53. {
  54. var p = q.Dequeue();
  55. ret.Add(p);
  56. foreach (var x in G[p])
  57. if (--count[x] == Capacity) q.Enqueue(x);
  58. }
  59. return ret.ToArray();
  60. }
  61.  
  62. }
  63. #endregion
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(9,16): error CS0161: `SuccessfulMerger.minimumMergers(int[])': not all code paths return a value
error CS5001: Program `prog.exe' does not contain a static `Main' method suitable for an entry point
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty