結果

問題 No.119 旅行のツアーの問題
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-10-18 10:52:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 86,216 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-23 09:10:58
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

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