結果

問題 No.654 Air E869120
ユーザー ___0_u_0______0_u_0___
提出日時 2018-09-17 17:42:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 6,641 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 72,432 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 07:46:45
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
5,376 KB
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:245:13: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=]
  245 |   scanf("%lld%lld%lld", &n, &m, &d);
      |          ~~~^           ~~
      |             |           |
      |             |           int*
      |             long long int*
      |          %d
main.cpp:245:17: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘int*’ [-Wformat=]
  245 |   scanf("%lld%lld%lld", &n, &m, &d);
      |              ~~~^           ~~
      |                 |           |
      |                 |           int*
      |                 long long int*
      |              %d
main.cpp:245:21: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int*’ [-Wformat=]
  245 |   scanf("%lld%lld%lld", &n, &m, &d);
      |                  ~~~^           ~~
      |                     |           |
      |                     |           int*
      |                     long long int*
      |                  %d
main.cpp:247:15: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=]
  247 |     scanf("%lld%lld%lld%lld%lld", &u[i], &v[i], &p[i], &q[i], &w[i]);
      |            ~~~^                   ~~~~~
      |               |                   |
      |               long long int*      int*
      |            %d
main.cpp:247:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘int*’ [-Wformat=]
  247 |     scanf("%lld%lld%lld%lld%lld", &u[i], &v[i], &p[i], &q[i], &w[i]);
      |                ~~~^                      ~~~~~
      |                   |                      |
      |                   long long int*         int*
      |                %d
main.cpp:247:23: warning: format ‘%lld’ expects argument of type ‘long long int*’

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/**** Const List   ****/

#define INF 1000000000
#define LLINF 100000000000000000

/**** Network Flow ****/

#define MAX_FLOW_MAX_V 10000
class MaxFlow {
public:
  struct edge { ll to, cap, rev; };

  vector<edge> G[MAX_FLOW_MAX_V];
  bool used[MAX_FLOW_MAX_V];
  ll level[MAX_FLOW_MAX_V];
  ll iter[MAX_FLOW_MAX_V];
  
  void init() {
    for (ll i = 0; i < MAX_FLOW_MAX_V; i++) {
      G[i].clear();
    }
  }
  void add_edge(ll from, ll to, ll cap) {
    G[from].push_back((edge){to, cap, (ll)G[to].size()});
    G[to].push_back((edge){from, 0, (ll)G[from].size() - 1});
  }
  void add_undirected_edge(ll e1, ll e2, ll cap) {
    G[e1].push_back((edge){e2, cap, (ll)G[e2].size()});
    G[e2].push_back((edge){e1, cap, (ll)G[e1].size() - 1});
  }
  ll dfs(ll v, ll t, ll f) {
    if (v == t) return f;
    used[v] = true;
    for (ll i = 0; i < (ll)G[v].size(); i++) {
      edge &e = G[v][i];
      if (!used[e.to]&& e.cap > 0) {
        ll d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  ll max_flow(ll s, ll t) {
    ll flow = 0;
    while (1) {
      memset(used, 0, sizeof(used));
      ll f = dfs(s, t, INF);
      if (f == 0) return flow;
      flow += f;
    }
  }
  void bfs(ll s) {
    memset(level, -1, sizeof(level));
    queue<ll> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      ll v = que.front(); que.pop();
      for (ll i = 0; i < (ll)G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  ll dinic_dfs(ll v, ll t, ll f) {
    if (v == t) return f;
    for (ll &i= iter[v]; i < (ll)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        ll d = dinic_dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  ll dinic(ll s, ll t) {
    ll flow = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      ll f;
      while ((f = dinic_dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
  }
};

/**** bipartite matching ****/

#define BIPARTITE_MATCHING_MAX_V 10000
class BipartiteMatching {
public:
  int V;
  vector<int> G[BIPARTITE_MATCHING_MAX_V];
  int match[BIPARTITE_MATCHING_MAX_V];
  bool used[BIPARTITE_MATCHING_MAX_V];
  
  BipartiteMatching(int v) {
    V = v;
  }
  void init(int v) {
    V = v;
    for (int i = 0; i < BIPARTITE_MATCHING_MAX_V; i++) {
      G[i].clear();
    }
  }
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < (int)G[v].size(); i++) {
      int u = G[v][i], w = match[u];
      if (w < 0 || !used[w] && dfs(w)) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
  int max_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for (int v = 0; v < V;v++) {
      if (match[v] < 0) {
        memset(used, 0, sizeof(used));
        if (dfs(v)) {
          res++;
        }
      }
    }
    return res;
  }
};

#define MIN_COST_FLOW_MAX_V 10000
class MinCostFlow {
public:
  struct edge { int to, cap, cost, rev; };

  int V;
  vector<edge> G[MIN_COST_FLOW_MAX_V];
  int dist[MIN_COST_FLOW_MAX_V];
  int prevv[MIN_COST_FLOW_MAX_V];
  int preve[MIN_COST_FLOW_MAX_V];

  MinCostFlow(int v) {
    V = v;
  }
  void init() {
    for (int i = 0; i < MAX_FLOW_MAX_V; i++) {
      G[i].clear();
    }
  }
  void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
  }
  void add_undirected_edge(int e1, int e2, int cap, int cost) {
    add_edge(e1, e2, cap, cost);
    add_edge(e2, e1, cap, cost);
  }
  int min_cost_flow(int s, int t, int f) { // minas
    int res = 0;
    while (f > 0) {
      fill(dist, dist + V, INF);
      dist[s] = 0;
      bool update = true;
      while (update) {
        update = false;
        for (int v = 0; v < V; v++) {
          if (dist[v] == INF) continue;
          for (int i = 0; i < (int)G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
              dist[e.to] = dist[v] + e.cost;
              prevv[e.to] = v;
              preve[e.to] = i;
              update = true;
            }
          }
        }
      }
      if (dist[t] == INF) {
        return -1;
      }
      int d = f;
      for (int v = t; v != s; v = prevv[v]) {
        d = min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * dist[t];
      for (int v = t; v != s; v = prevv[v]) {
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
  int min_cost_flow_dijkstra(int s, int t, int f) {
    int res = 0;
    //fill(h, h + V, 0);
    while (f > 0) {
      priority_queue<P, vector<P>, greater<P> > que;
      //fill(dist,
      // あとで書く
    }
    return 0;
  }
};

int n, m, d;
int u[1000], v[1000], p[1000], q[1000], w[1000];
vector<int> E[1000];
int num[1000], endnum;
MaxFlow f;

int main() {
  scanf("%lld%lld%lld", &n, &m, &d);
  for (ll i = 0; i < m; i++) {
    scanf("%lld%lld%lld%lld%lld", &u[i], &v[i], &p[i], &q[i], &w[i]);
    u[i]--; v[i]--;
    E[u[i]].push_back(p[i]);
  }
  ll temp = 0;
  for (ll i = 0; i < n; i++) {
    num[i] = temp;
    temp += (ll)E[i].size();
    sort(E[i].begin(), E[i].end());
  }
  endnum = temp + 1;
  for (ll i = 0; i < m; i++) {
    ll from = u[i], to = v[i], time = q[i] + d;
    ll size = (ll)E[to].size(), j, fromnumber = 0;
    while (E[from][fromnumber] != p[i]) fromnumber++;
    fromnumber += num[from];
    if (to == n - 1) {
      f.add_edge(fromnumber, endnum, w[i]);
      continue;
    }
    if (time > E[to][size - 1]) continue;
    for (j = 0; j < size; j++) {
      if (time <= E[to][j]) break;
    }
    ll tonumber = j + num[to];
    f.add_edge(fromnumber, tonumber, w[i]);
  }
  for (ll i = 0; i < n; i++) {
    ll size = (ll)E[i].size();
    for (ll j = 0; j < size - 1; j++) {
      f.add_edge(num[i] + j, num[i] + j + 1, LLINF);
    }
  }
  printf("%lld\n", f.dinic(0, endnum));
}
0