結果

問題 No.119 旅行のツアーの問題
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-01-07 00:02:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,595 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 85,128 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 09:11:22
合計ジャッジ時間 1,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000009

#define NN 82
#define INF 100000000

int v[NN][NN];
int flag[NN];

int flow(int s, int e, int f){
  if(s == e)return f;

  flag[s] = 1;

  for(int i = 0; i < NN; i++){
    if(v[s][i] > 0 && flag[i] == 0){
      int d = flow(i, e, min(f, v[s][i]));
      if(d > 0){
        v[s][i] -= d;
        v[i][s] += d;
        return d;
      }
    }
  }
  return 0;
}

void ae(int from, int to, int cost){
  v[from][to] = cost;
  v[to][from] = 0;
}

int main(){
  clr(v,-1);
  int sum = 0;
  int n;
  cin >> n;
  rep(i,0,n){
    int b,c;
    cin >> b >> c;
    ae(2*n,i,b);
    ae(i+n,2*n+1,c);
    ae(i,i+n,INF);
    sum += b+c;
  }
  int m;
  cin >> m;
  rep(i,0,m){
    int d,e;
    cin >> d >> e;
    ae(d,e+n,INF);
  }
  int ans = 0;
  for(;;){
    memset(flag,0,sizeof(flag));
    int f = flow(2*n,2*n+1, INF);
    if(f == 0)break;
    ans += f;
  }
  cout << sum-ans << endl;
  return 0;
}

/*
追加した辺の逆辺に 0 を入れていなかったところを修正。
*/
0