結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | kzyKT |
提出日時 | 2020-11-28 14:47:41 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,355 bytes |
コンパイル時間 | 2,269 ms |
コンパイル使用メモリ | 147,348 KB |
実行使用メモリ | 42,768 KB |
最終ジャッジ日時 | 2023-10-10 00:01:53 |
合計ジャッジ時間 | 19,400 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,632 KB |
testcase_01 | AC | 3 ms
6,568 KB |
testcase_02 | AC | 291 ms
41,848 KB |
testcase_03 | AC | 265 ms
38,544 KB |
testcase_04 | AC | 335 ms
38,552 KB |
testcase_05 | AC | 252 ms
42,768 KB |
testcase_06 | AC | 329 ms
36,276 KB |
testcase_07 | AC | 319 ms
39,292 KB |
testcase_08 | AC | 213 ms
39,072 KB |
testcase_09 | AC | 310 ms
34,844 KB |
testcase_10 | AC | 226 ms
38,092 KB |
testcase_11 | AC | 319 ms
37,508 KB |
testcase_12 | AC | 315 ms
37,556 KB |
testcase_13 | AC | 312 ms
42,036 KB |
testcase_14 | AC | 276 ms
34,976 KB |
testcase_15 | AC | 285 ms
36,680 KB |
testcase_16 | AC | 308 ms
38,420 KB |
testcase_17 | AC | 350 ms
41,984 KB |
testcase_18 | AC | 312 ms
38,932 KB |
testcase_19 | AC | 283 ms
36,464 KB |
testcase_20 | AC | 323 ms
35,068 KB |
testcase_21 | AC | 270 ms
40,672 KB |
testcase_22 | AC | 304 ms
35,748 KB |
testcase_23 | AC | 386 ms
42,248 KB |
testcase_24 | AC | 301 ms
35,716 KB |
testcase_25 | AC | 332 ms
39,148 KB |
testcase_26 | AC | 282 ms
38,392 KB |
testcase_27 | AC | 312 ms
38,164 KB |
testcase_28 | AC | 296 ms
42,568 KB |
testcase_29 | AC | 370 ms
37,828 KB |
testcase_30 | AC | 409 ms
39,212 KB |
testcase_31 | AC | 381 ms
38,276 KB |
testcase_32 | AC | 4 ms
6,744 KB |
testcase_33 | AC | 93 ms
33,460 KB |
testcase_34 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; const int MAX_V= 100002; struct edge{ ll to,cap,cost,rev; edge(ll to,ll cap,ll cost,ll rev) : to(to),cap(cap),cost(cost),rev(rev) {} }; vector<edge> G[MAX_V]; ll dist[MAX_V]; ll prevv[MAX_V],preve[MAX_V]; void add_edge(ll from,ll to,ll cap,ll cost){ G[from].push_back(edge(to,cap,cost,G[to].size())); G[to].push_back(edge(from,0,-cost,G[from].size()-1)); } ll min_cost_flow(ll s,ll t,ll f){ ll res = 0; while(f>0){ fill(dist,dist+MAX_V,MAXL); dist[s] = 0; bool update=true; while(update){ update=false; for(ll v=0; v<MAX_V; v++){ if(dist[v]==MAXL) continue; for(ll 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]==MAXL) return -1; ll d = f; for(ll v=t; v!=s; v=prevv[v]){ d=min(d,G[prevv[v]][preve[v]].cap); } f-=d;res+=d*dist[t]; for(ll 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; } void Main() { ll n,m; cin >> n >> m; rep(i,m) { ll x,y,z1,z2; cin >> x >> y >> z1 >> z2; x--,y--; add_edge(x,y,1,z1); add_edge(y,x,1,z1); add_edge(x,y,1,z2); add_edge(y,x,1,z2); } pr(min_cost_flow(0,n-1,2)); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}