結果
問題 | No.654 Air E869120 |
ユーザー |
![]() |
提出日時 | 2018-06-29 15:26:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,776 bytes |
コンパイル時間 | 967 ms |
コンパイル使用メモリ | 96,596 KB |
最終ジャッジ日時 | 2025-01-06 11:39:11 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 WA * 1 TLE * 14 |
ソースコード
#include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define rep(i,n) for(int i=0;i<(n);i++) #define MAX_V (1001) struct edge { P to; ll cap; ll rev_id; }; map<P,vector<edge> > G; set<P> used; void add_edge(P from,P 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}); } ll dfs(P v,P t,ll f) { if(v == t)return f; used.insert(v); rep(i,G[v].size()) { edge &e = G[v][i]; if(used.find(e.to) == used.end() && e.cap > 0) { ll d = dfs(e.to,t,min(f,e.cap)); if(d > 0) { e.cap -= d; G[e.to][e.rev_id].cap += d; return d; } } } return 0; } ll max_flow(P s/*始点*/,P t/*終点*/) { ll flow = 0; for(;;) { used.clear(); ll f = dfs(s,t,10000000000); if(f == 0)break; flow += f; } return flow; } ll N,M,d,u[1001],v[1001],p[1001],q[1001],w[1001]; int main() { cin >> N >> M >> d; rep(i,M) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i]; rep(i,M) { u[i]--;v[i]--; G[P(u[i],p[i])] = vector<edge>(); G[P(v[i],q[i])] = vector<edge>(); } G[P(0,-d)] = vector<edge>(); G[P(N-1,1000000000)] = vector<edge>(); rep(i,M) { add_edge(P(u[i],p[i]),P(v[i],q[i]),w[i]); } for(auto x : G) { for(auto y : G) { if(x.first.first == y.first.first && x.first.second + d <= y.first.second) { add_edge(x.first,y.first,1000000000); } } } cout << max_flow(P(0,-d),P(N-1,1000000000)) << endl; return 0; }