結果

問題 No.119 旅行のツアーの問題
ユーザー umezoumezo
提出日時 2024-04-03 23:05:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 853 bytes
コンパイル時間 3,822 ms
コンパイル使用メモリ 259,808 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-03 23:05:24
合計ジャッジ時間 4,276 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0