結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-28 14:47:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,355 bytes |
| コンパイル時間 | 2,245 ms |
| コンパイル使用メモリ | 163,000 KB |
| 実行使用メモリ | 49,284 KB |
| 最終ジャッジ日時 | 2024-09-12 22:29:07 |
| 合計ジャッジ時間 | 16,855 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 TLE * 1 |
ソースコード
#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;}