結果
問題 | No.119 旅行のツアーの問題 |
ユーザー | shiomusubi496 |
提出日時 | 2021-09-05 19:52:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,943 bytes |
コンパイル時間 | 2,114 ms |
コンパイル使用メモリ | 213,492 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-02 02:38:30 |
合計ジャッジ時間 | 2,989 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In instantiation of 'int MaxFlowGraph<Cap>::add_edge(int, int, Cap) [with Cap = int]': main.cpp:67:15: required from here main.cpp:14:37: warning: narrowing conversion of '(&((MaxFlowGraph<int>*)this)->MaxFlowGraph<int>::G.std::vector<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >, std::allocator<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> > > >::operator[](((std::vector<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >, std::allocator<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> > > >::size_type)b)))->std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >::size()' from 'std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 14 | G[a].push_back({b, G[b].size(), edg.size(), c}); | ~~~~~~~~~^~ main.cpp:14:49: warning: narrowing conversion of '((MaxFlowGraph<int>*)this)->MaxFlowGraph<int>::edg.std::vector<MaxFlowGraph<int>::edge, std::allocator<MaxFlowGraph<int>::edge> >::size()' from 'std::vector<MaxFlowGraph<int>::edge, std::allocator<MaxFlowGraph<int>::edge> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 14 | G[a].push_back({b, G[b].size(), edg.size(), c}); | ~~~~~~~~^~ main.cpp:15:39: warning: narrowing conversion of '((&((MaxFlowGraph<int>*)this)->MaxFlowGraph<int>::G.std::vector<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >, std::allocator<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> > > >::operator[](((std::vector<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> >, std::allocator<std::vector<MaxFlowGraph<int>::edge_, std::allocator<MaxFlowGraph<int>::edge_> > > >::size_type)a)))->std::vector<MaxF
ソースコード
#include<bits/stdc++.h> using namespace std; template<class Cap> struct MaxFlowGraph{ struct edge{ int from, to; Cap cap, flow; }; MaxFlowGraph(int n): G(n), _n(n), cap_max(0){} int add_edge(int a, int b, Cap c){ assert(0<=a && a<_n); assert(0<=b && b<_n); assert(0<=c); G[a].push_back({b, G[b].size(), edg.size(), c}); G[b].push_back({a, G[a].size()-1, ~(int)edg.size(), 0}); edg.push_back({a, b, c, 0}); if(cap_max < c) cap_max = c; return edg.size()-1; } Cap flow(int s, int t){ Cap res = 0; while(true){ used.assign(_n, false); Cap fw = dfs(s, t, cap_max); if(fw==0)break; res += fw; } return res; } std::vector<edge> edges(){return edg;} edge get_edge(int k){return edg[k];} private: struct edge_{ int to, rev, id; Cap cap; }; int _n; Cap cap_max; std::vector<std::vector<edge_>> G; std::vector<edge> edg; std::vector<bool> used; Cap dfs(int v, int t, Cap f){ if(v==t) return f; used[v] = true; for(edge_ &e:G[v]){ if(used[e.to] || e.cap==0) continue; Cap fw = dfs(e.to, t, std::min<Cap>(f, e.cap)); if(fw==0) continue; e.cap -= fw; G[e.to][e.rev].cap += fw; if(e.id<0) edg[~e.id].flow -= fw; else edg[e.id].flow += fw; return fw; } return 0; } }; constexpr int INF=1e9; int main(){ int N; cin>>N; int s=2*N,t=s+1; MaxFlowGraph<int> G(2*N+2); int sum=0; for(int i=0;i<N;i++){ int B,C; cin>>B>>C; sum+=B+C; G.add_edge(s,i,B); G.add_edge(N+i,t,C); } for(int i=0;i<N;i++)G.add_edge(i,N+i,INF); int M; cin>>M; for(int i=0;i<M;i++){ int a,b; cin>>a>>b; G.add_edge(a,N+b,INF); } cout<<sum-G.flow(s,t)<<endl; }