結果
問題 | No.119 旅行のツアーの問題 |
ユーザー |
![]() |
提出日時 | 2024-04-03 23:05:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 853 bytes |
コンパイル時間 | 3,079 ms |
コンパイル使用メモリ | 259,464 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 00:09:08 |
合計ジャッジ時間 | 3,899 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)#define ALL(v) v.begin(),v.end()typedef long long ll;#include <bits/stdc++.h>#include <atcoder/maxflow>using namespace std;using namespace atcoder;template <class T> using V=vector<T>;template <class T> using VV=V<V<T>>; //B(n,V<int>(n))const ll INF=1e18;int main(){ios::sync_with_stdio(false);std::cin.tie(nullptr);int n;cin>>n;ll sum=0;V<ll> B(n),C(n),MA(n);rep(i,n){cin>>B[i]>>C[i];MA[i]=B[i]+C[i];sum+=MA[i];}int m;cin>>m;V<ll> D(m),E(m);rep(i,m) cin>>D[i]>>E[i];mf_graph<ll> graph(2*n+2);int s=2*n,t=2*n+1;rep(i,n) graph.add_edge(s,i,MA[i]-C[i]);rep(i,n) graph.add_edge(i,i+n,MA[i]);rep(i,n) graph.add_edge(i+n,t,MA[i]-B[i]);rep(i,m) graph.add_edge(D[i],E[i]+n,INF);cout<<sum-graph.flow(s,t)<<endl;return 0;}