結果

問題 No.654 Air E869120
ユーザー shiomusubi496shiomusubi496
提出日時 2021-09-05 13:12:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 218,676 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 14:11:06
合計ジャッジ時間 4,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
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 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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: 警告: 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: 警告: 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’ 

ソースコード

diff #

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