結果
| 問題 | No.654 Air E869120 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-09-05 13:12:39 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 50 ms / 2,000 ms | 
| コード長 | 1,953 bytes | 
| コンパイル時間 | 2,435 ms | 
| コンパイル使用メモリ | 213,392 KB | 
| 最終ジャッジ日時 | 2025-01-24 08:19:48 | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 35 | 
コンパイルメッセージ
main.cpp: In instantiation of ‘void MaxFlowGraph<Cap>::add_edge(int, int, Cap) [with Cap = long long int]’:
main.cpp:55:15:   required from here
main.cpp:13:37: warning: narrowing conversion of ‘(&((MaxFlowGraph<long long int>*)this)->MaxFlowGraph<long long int>::G.std::vector<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >, std::allocator<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> > > >::operator[](((std::vector<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >, std::allocator<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> > > >::size_type)b)))->std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >::size()’ from ‘std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   13 |         G[a].push_back({b, G[b].size(), c});
      |                            ~~~~~~~~~^~
main.cpp:14:39: warning: narrowing conversion of ‘((&((MaxFlowGraph<long long int>*)this)->MaxFlowGraph<long long int>::G.std::vector<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >, std::allocator<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> > > >::operator[](((std::vector<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >, std::allocator<std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> > > >::size_type)a)))->std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >::size() - 1)’ from ‘std::vector<MaxFlowGraph<long long int>::edge, std::allocator<MaxFlowGraph<long long int>::edge> >::size_type��
            
            ソースコード
#include<bits/stdc++.h>
using namespace std;
template<class Cap> struct MaxFlowGraph{
    struct edge{
        int to, rev;
        Cap cap;
    };
    MaxFlowGraph(int n): G(n), _n(n), cap_max(0){}
    void add_edge(int a, int b, Cap c){
        assert(0<=a && a<_n);
        assert(0<=b && b<_n);
        assert(0<=c);
        G[a].push_back({b, G[b].size(), c});
        G[b].push_back({a, G[a].size()-1, 0});
        if(cap_max < c) cap_max = c;
    }
    Cap flow(int s, int t){
        Cap res = 0;
        while(true){
            used.assign(_n, false);
            Cap fw = dfs(s, t, cap_max);
            if(fw==0)break;
            res += fw;
        }
        return res;
    }
    private:
    int _n;
    Cap cap_max;
    std::vector<std::vector<edge>> G;
    std::vector<bool> used;
    Cap dfs(int v, int t, Cap f){
        if(v==t) return f;
        used[v] = true;
        for(edge &e:G[v]){
            if(used[e.to] || e.cap==0) continue;
            Cap fw = dfs(e.to, t, min(f, e.cap));
            if(fw==0) continue;
            e.cap -= fw;
            G[e.to][e.rev].cap += fw;
            return fw;
        }
        return 0;
    }
};
int main(){
  int N,M,d; cin>>N>>M>>d;
  int s=2*M,t=s+1;
  MaxFlowGraph<long long> G(2*M+2);
  vector<int> U(M),V(M),P(M),Q(M),W(M);
  vector<vector<pair<int,int>>> A(N);
  for(int i=0;i<M;i++){
    cin>>U[i]>>V[i]>>P[i]>>Q[i]>>W[i];
    --U[i]; --V[i];
    G.add_edge(2*i,2*i+1,W[i]);
    if(U[i]==0)G.add_edge(s,2*i,W[i]);
    if(V[i]==N-1)G.add_edge(2*i+1,t,W[i]);
    A[U[i]].push_back({P[i],i});
  }
  for(int i=0;i<N;i++){
    sort(A[i].begin(),A[i].end());
    for(int j=0;j+1<A[i].size();j++)G.add_edge(A[i][j].second*2,A[i][j+1].second*2,1e18);
  }
  for(int i=0;i<M;i++){
    int itr=lower_bound(A[V[i]].begin(),A[V[i]].end(),pair(Q[i]+d,0))-A[V[i]].begin();
    if(itr==A[V[i]].size())continue;
    G.add_edge(i*2+1,A[V[i]][itr].second*2,1e18);
  }
  cout<<G.flow(s,t)<<endl;
}
            
            
            
        