結果
問題 | No.119 旅行のツアーの問題 |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-01-15 19:01:05 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,869 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 91,152 KB |
実行使用メモリ | 51,160 KB |
最終ジャッジ日時 | 2024-06-06 11:31:38 |
合計ジャッジ時間 | 4,962 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
37,332 KB |
testcase_01 | AC | 76 ms
37,740 KB |
testcase_02 | AC | 60 ms
37,396 KB |
testcase_03 | AC | 60 ms
37,256 KB |
testcase_04 | AC | 59 ms
37,268 KB |
testcase_05 | AC | 63 ms
37,772 KB |
testcase_06 | WA | - |
testcase_07 | AC | 60 ms
37,268 KB |
testcase_08 | AC | 59 ms
37,248 KB |
testcase_09 | AC | 61 ms
37,536 KB |
testcase_10 | AC | 59 ms
37,272 KB |
testcase_11 | AC | 59 ms
37,472 KB |
testcase_12 | AC | 60 ms
37,208 KB |
testcase_13 | AC | 61 ms
37,204 KB |
testcase_14 | AC | 63 ms
37,980 KB |
testcase_15 | AC | 65 ms
37,560 KB |
testcase_16 | AC | 81 ms
38,784 KB |
testcase_17 | AC | 60 ms
37,168 KB |
testcase_18 | AC | 67 ms
37,516 KB |
testcase_19 | AC | 63 ms
37,416 KB |
testcase_20 | AC | 77 ms
38,272 KB |
testcase_21 | AC | 86 ms
38,696 KB |
testcase_22 | AC | 93 ms
38,880 KB |
ソースコード
import java.io.*; import java.util.*; class Main { static ArrayList<Long>[] g; static void add(int a, int b, int c){ g[a].add((long)b<<32|c); } @SuppressWarnings("unchecked") public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int[]b=new int[n],c=new int[n]; g=new ArrayList[3*n+2]; Arrays.setAll(g,x->new ArrayList<Long>()); for(int i=0;i<n;++i){ b[i]=sc.nextInt(); c[i]=sc.nextInt(); add(0,2+i,1<<28); add(2+i,2+n+i,100-b[i]); add(2+n+i,2+i,1<<28); add(2+n+i,2+2*n+i,100); add(2+2*n+i,2+n+i,1<<28); add(2+2*n+i,1,100-c[i]); } int m=sc.nextInt(); for(int i=0;i<m;++i){ int d=sc.nextInt(); int e=sc.nextInt(); add(2+2*n+e,2+n+d,1<<28); } long ans=Dinic.maximumFlow(g,0,1); out.println(100*n-ans); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n){ int[]r=new int[n]; for(int i=0;i<n;++i)r[i]=nextInt(); return r; } } } /* 参考: http://www.prefield.com/algorithm/graph/dinic.html */ class Dinic{ //#define RESIDUE(s,t) (capacity[s][t]-flow[s][t]) static final long INF=1L<<55; static long augment(ArrayList<Long>[] g, long[][] capacity, long[][] flow, int[] level, boolean[] finished, int u, int t, long cur) { if (u == t || cur == 0) return cur; if (finished[u]) return 0; finished[u] = true; for(long e:g[u]){ int dst=(int)(e>>>32); int wei=(int)e; if (level[dst] > level[u]) { long f = augment(g, capacity, flow, level, finished, dst, t, Math.min(cur, capacity[u][dst]-flow[u][dst])); if (f > 0) { flow[u][dst] += f; flow[dst][u] -= f; finished[u] = false; return f; } } } return 0; } // g[i][j] = (dest)<<32|(cap) static long maximumFlow(ArrayList<Long>[] g, int s, int t) { int n = g.length; long[][]flow=new long[n][n], cap=new long[n][n]; // adj. matrix for(int u=0;u<n;++u) for(long e:g[u]){ int dst=(int)(e>>>32); int wei=(int)e; cap[u][dst] += wei; } long total = 0; for (boolean cont = true; cont; ) { cont = false; int[] level=new int[n]; Arrays.fill(level, -1); level[s] = 0; // make layered network Queue<Integer> q=new ArrayDeque<Integer>(); q.add(s); for (int d = n; q.size()>0 && level[q.peek()] < d; ) { int u=q.poll(); if (u == t) d = level[u]; for(long e:g[u]){ int dst=(int)(e>>>32); int wei=(int)e; if(cap[u][dst]>flow[u][dst] && level[dst] == -1) { q.add(dst); level[dst]=level[u]+1; } } } boolean[] finished=new boolean[n];// make blocking flows for (long f = 1; f > 0; ) { f = augment(g, cap, flow, level, finished, s, t, INF); if (f == 0) break; total += f; cont = true; } } return total; } }