Submission #181456
Source Code Expand
using System; using System.Collections; using System.Collections.Generic; class Myon { public Myon() { } public static int Main() { new Myon().calc(); return 0; } void calc() { string[] st = splitLine(3, 3); int N = getInt(st[0], 1, 100); int G = getInt(st[1], 0, N - 1); int E = getInt(st[2], 0, N * (N - 1) / 2); int[] p = new int[G]; st = splitLine(G, G); for (int i = 0; i < G; i++) { p[i] = getInt(st[i], 1, N - 1); } int[] a = new int[E]; int[] b = new int[E]; for (int i = 0; i < E; i++) { st = splitLine(2, 2); a[i] = getInt(st[0], 0, N - 1); b[i] = getInt(st[1], 0, N - 1); if (a[i] == b[i]) myon("!?"); } V[] vs = new V[N]; for (int i = 0; i < N; i++) { vs[i] = new V(); } V goal = new V(); for (int i = 0; i < E; i++) { vs[a[i]].add(vs[b[i]], 1); } for (int i = 0; i < G; i++) { vs[p[i]].add(goal, 1); } Console.WriteLine(dinic(vs[0], goal)); } long INF = 1L << 62; long dinic(V s, V t) { long flow = 0; for (int p = 1; ; p++) { Queue<V> que = new Queue<V>(); s.level = 0; s.p = p; que.Enqueue(s); while (que.Count != 0) { V v = que.Dequeue(); v.iter = v.es.Count - 1; foreach (E e in v.es) { if (e.to.p < p && e.cap > 0) { e.to.level = v.level + 1; e.to.p = p; que.Enqueue(e.to); } } } if (t.p < p) return flow; for (long f = 0; (f = dfs(s, t, INF)) > 0; ) { flow += f; } } } long dfs(V v, V t, long f) { if (v == t) return f; for (; v.iter >= 0; v.iter--) { E e = v.es[v.iter]; if (v.level < e.to.level && e.cap > 0) { long d = dfs(e.to, t, Math.Min(f, e.cap)); if (d > 0) { e.cap -= d; e.rev.cap += d; return d; } } } return 0; } class V { public V() { } public List<E> es = new List<E>(); public int level, p, iter; public void add(V to, long cap) { E e = new E(to, cap); E rev = new E(this, cap); e.rev = rev; rev.rev = e; es.Add(e); to.es.Add(rev); } } class E { public V to; public E rev; public long cap; public E(V to, long cap) { this.to = to; this.cap = cap; } } //swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } void myon(string s) { throw new Exception(s); } int getInt(string s, int min, int max) { int ret = int.Parse(s); if (ret < min) throw new Exception("low"); if (ret > max) throw new Exception("high"); return ret; } int getIntLine(int min, int max) { int ret = int.Parse(Console.ReadLine()); if (ret < min) throw new Exception("low"); if (ret > max) throw new Exception("high"); return ret; } double getDouble(string s, double min, double max) { double ret = double.Parse(s); if (ret < min) throw new Exception("low"); if (ret > max) throw new Exception("high"); return ret; } double getDoubleLine(double min, double max) { double ret = double.Parse(Console.ReadLine()); if (ret < min) throw new Exception("low"); if (ret > max) throw new Exception("high"); return ret; } string getString(string s, int min, int max) { if (s.Length < min) throw new Exception("low"); if (s.Length > max) throw new Exception("high"); return s; } string getStringLine(int min, int max) { string s = Console.ReadLine(); if (s.Length < min) throw new Exception("low"); if (s.Length > max) throw new Exception("high"); return s; } string[] splitLine(int min, int max) { string[] ret = Console.ReadLine().Split(' '); if (ret.Length == 1 && ret[0] == "") ret = new string[0]; if (ret.Length < min || ret.Length > max) throw new Exception("wrong length"); return ret; } }
Submission Info
Submission Time | |
---|---|
Task | D - 浮気予防 |
User | chokudai |
Language | C# (Mono 2.10.8.1) |
Score | 100 |
Code Size | 5088 Byte |
Status | AC |
Exec Time | 169 ms |
Memory | 9864 KB |
Judge Result
Set Name | part | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 99 / 99 | 1 / 1 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
part | test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_41_AB.txt, test_47_AB.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_26_A.txt, test_27_A.txt, test_28_A.txt, test_29_A.txt, test_30_A.txt, test_31_A.txt, test_32_A.txt, test_33_A.txt, test_34_A.txt, test_35_A.txt, test_36_A.txt, test_37_A.txt, test_38_A.txt, test_39_A.txt, test_40_A.txt, test_41_AB.txt, test_42_A.txt, test_43_A.txt, test_44_A.txt, test_45_A.txt, test_46_A.txt, test_47_AB.txt, test_48_A.txt, test_49_A.txt, test_50_A.txt, test_51_A.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 149 ms | 8972 KB |
sample_02.txt | AC | 150 ms | 8972 KB |
sample_03.txt | AC | 154 ms | 9144 KB |
sample_04.txt | AC | 151 ms | 9044 KB |
sample_05.txt | AC | 151 ms | 9036 KB |
test_01_AB.txt | AC | 151 ms | 9012 KB |
test_02_AB.txt | AC | 160 ms | 9112 KB |
test_03_AB.txt | AC | 150 ms | 9044 KB |
test_04_AB.txt | AC | 151 ms | 9020 KB |
test_05_AB.txt | AC | 153 ms | 9044 KB |
test_06_AB.txt | AC | 156 ms | 9044 KB |
test_07_AB.txt | AC | 149 ms | 9108 KB |
test_08_AB.txt | AC | 147 ms | 8972 KB |
test_09_AB.txt | AC | 150 ms | 9036 KB |
test_10_AB.txt | AC | 148 ms | 9048 KB |
test_11_AB.txt | AC | 152 ms | 9044 KB |
test_12_AB.txt | AC | 151 ms | 9036 KB |
test_13_AB.txt | AC | 148 ms | 9040 KB |
test_14_AB.txt | AC | 146 ms | 9036 KB |
test_15_AB.txt | AC | 150 ms | 9044 KB |
test_16_AB.txt | AC | 154 ms | 9104 KB |
test_17_AB.txt | AC | 152 ms | 9080 KB |
test_18_AB.txt | AC | 148 ms | 9048 KB |
test_19_AB.txt | AC | 147 ms | 9100 KB |
test_20_AB.txt | AC | 147 ms | 9044 KB |
test_21_AB.txt | AC | 147 ms | 9032 KB |
test_22_AB.txt | AC | 149 ms | 9040 KB |
test_23_AB.txt | AC | 148 ms | 9040 KB |
test_24_AB.txt | AC | 145 ms | 9016 KB |
test_25_AB.txt | AC | 149 ms | 9036 KB |
test_26_A.txt | AC | 158 ms | 9800 KB |
test_27_A.txt | AC | 160 ms | 9852 KB |
test_28_A.txt | AC | 159 ms | 9744 KB |
test_29_A.txt | AC | 160 ms | 9864 KB |
test_30_A.txt | AC | 163 ms | 9796 KB |
test_31_A.txt | AC | 160 ms | 9728 KB |
test_32_A.txt | AC | 154 ms | 9264 KB |
test_33_A.txt | AC | 158 ms | 9540 KB |
test_34_A.txt | AC | 169 ms | 9172 KB |
test_35_A.txt | AC | 155 ms | 9160 KB |
test_36_A.txt | AC | 152 ms | 9152 KB |
test_37_A.txt | AC | 155 ms | 9344 KB |
test_38_A.txt | AC | 151 ms | 9044 KB |
test_39_A.txt | AC | 163 ms | 9044 KB |
test_40_A.txt | AC | 148 ms | 9148 KB |
test_41_AB.txt | AC | 149 ms | 9108 KB |
test_42_A.txt | AC | 153 ms | 9284 KB |
test_43_A.txt | AC | 152 ms | 9044 KB |
test_44_A.txt | AC | 154 ms | 9288 KB |
test_45_A.txt | AC | 150 ms | 9044 KB |
test_46_A.txt | AC | 151 ms | 9040 KB |
test_47_AB.txt | AC | 152 ms | 9044 KB |
test_48_A.txt | AC | 154 ms | 9084 KB |
test_49_A.txt | AC | 153 ms | 9044 KB |
test_50_A.txt | AC | 149 ms | 9172 KB |
test_51_A.txt | AC | 152 ms | 9180 KB |