結果

問題 No.654 Air E869120
ユーザー 5_25_1255_25_125
提出日時 2018-09-18 00:15:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,054 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 93,504 KB
実行使用メモリ 8,556 KB
最終ジャッジ日時 2023-09-25 09:40:28
合計ジャッジ時間 6,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,556 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 299 ms
4,380 KB
testcase_11 AC 116 ms
4,376 KB
testcase_12 AC 185 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 301 ms
4,376 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>

#define LLINF 100000000000000000LL
#define DIV 2147483647LL

typedef long long ll;

using namespace std;

typedef unordered_map<ll,unordered_map<ll,ll>> double_map;

ll dfs(double_map &g, ll pos, ll end, ll flow, unordered_map<ll,bool> &arrived) {
    if(pos==end) return flow;
    arrived[pos] = true;
    for(pair<ll,ll> p : g[pos]) {
        ll next = p.first;
        ll capacity = p.second;
        if(!arrived[next]&&capacity>0) {
            ll res = dfs(g,next,end,min(flow,capacity),arrived);
            if(res>0) {
                g[pos][next] -= res;
                g[next][pos] += res;
                //if(g[pos][next]<=0) g[pos].erase(next);
                return res;
            }
        }
    }
    return 0;
}

ll max_flow(double_map &g, ll s, ll e) {
    ll ans = 0;
    while(true) {
        unordered_map<ll,bool> arrived;
        ll flow = dfs(g,s,e,1LL<<60,arrived);
        if(flow<=0) break;
        else ans += flow;
    }
    return ans;
}

int main() {
  ll n,m,d;
  cin >> n >> m >> d;
  ll e = 1000000000LL+d;
  ll input[1000][5];
  map<ll,bool> times[1000];
  for(int i = 0; i < m; i++) {
    cin >> input[i][0] >> input[i][1] >> input[i][2] >> input[i][3] >> input[i][4];
    input[i][0]--; input[i][1]--;
    input[i][3]+=d;
    times[input[i][0]].insert(make_pair(input[i][2],true));
    times[input[i][1]].insert(make_pair(input[i][3],true));
  }
  times[n-1].insert(make_pair(e,true));

  double_map dm;

  for(int i = 0; i < n; i++) {
    pair<ll,bool> pre_p(0,false);
    for(pair<ll,bool> p : times[i]) {
      ll pre_t = pre_p.first;
      ll t = p.first;
      dm[i*DIV+pre_t][i*DIV+t] = LLINF;
      pre_p = p;
    }
  }
  for(int i = 0; i < m; i++) {
    ll u = input[i][0];
    ll v = input[i][1];
    ll p = input[i][2];
    ll q = input[i][3];
    ll w = input[i][4];
    if(u!=n-1) {
      dm[u*DIV+p][v*DIV+q] = w;
      dm[v*DIV+q][u*DIV+p] = 0;
    }
  }

  ll ans = max_flow(dm,0,(n-1)*DIV+e);

  cout << ans << endl;
}
0