結果

問題 No.654 Air E869120
ユーザー ___0_u_0______0_u_0___
提出日時 2018-09-17 17:38:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 6,677 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 71,688 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-18 07:46:43
合計ジャッジ時間 2,284 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
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 AC 2 ms
5,376 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:245:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  245 |   scanf("%d%d%d", &n, &m, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:247:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  247 |     scanf("%d%d%d%d%d", &u[i], &v[i], &p[i], &q[i], &w[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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 { int to, cap, rev; };

  vector<edge> G[MAX_FLOW_MAX_V];
  bool used[MAX_FLOW_MAX_V];
  int level[MAX_FLOW_MAX_V];
  int iter[MAX_FLOW_MAX_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) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
  }
  void add_undirected_edge(int e1, int e2, int cap) {
    G[e1].push_back((edge){e2, cap, (int)G[e2].size()});
    G[e2].push_back((edge){e1, cap, (int)G[e1].size() - 1});
  }
  int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (!used[e.to]&& e.cap > 0) {
        int 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;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      memset(used, 0, sizeof(used));
      int f = dfs(s, t, INF);
      if (f == 0) return flow;
      flow += f;
    }
  }
  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)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);
        }
      }
    }
  }
  int dinic_dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i= iter[v]; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int 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;
  }
  int dinic(int s, int t) {
    int flow = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int 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("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d%d", &u[i], &v[i], &p[i], &q[i], &w[i]);
    u[i]--; v[i]--;
    E[u[i]].push_back(p[i]);
  }
  int temp = 0;
  for (int i = 0; i < n; i++) {
    num[i] = temp;
    temp += (int)E[i].size();
    sort(E[i].begin(), E[i].end());
  }
  endnum = temp + 1;
  for (int i = 0; i < m; i++) {
    int from = u[i], to = v[i], time = q[i] + d;
    int size = (int)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;
    }
    int tonumber = j + num[to];
    f.add_edge(fromnumber, tonumber, w[i]);
  }
  for (int i = 0; i < n; i++) {
    int size = (int)E[i].size();
    for (int j = 0; j < size - 1; j++) {
      f.add_edge(num[i] + j, num[i] + j + 1, INF);
    }
  }
  printf("%d\n", f.dinic(0, endnum));
}
0