求找错!!!!!!

P2153 [SDOI2009] 晨跑

```cpp #include <bits/stdc++.h> using namespace std; struct line { int u,v,nxt,cap,price; } datas [1000002]; int head [10002],cnt = 1; inline void add (int a,int b,int w,int p) { datas [++ cnt].v = b; datas [cnt].u = a; datas [cnt].cap = w; datas [cnt].nxt = head [a]; datas [cnt].price = p; head [a] = cnt; } int n,m,s,t; int dis [10002],flow [10002],pre [10002]; bool inq [10002]; int cost; inline int bfs () { queue<int> q;q.push (s); memset (flow,0,sizeof flow);memset (dis,0x3f,sizeof dis); memset (inq,false,sizeof inq); dis [s] = 0;flow [s] = 0x3f3f3f3f; while (!q.empty ()) { int u = q.front ();q.pop ();inq [u] = false; if (u == t) { break ; } for (int ptr = head [u];ptr;ptr = datas [ptr].nxt) { int d = datas [ptr].price,cap = datas [ptr].cap,v = datas [ptr].v; if (!cap) { continue; } if (dis [v] > dis [u] + d) { dis [v] = dis [u] + d; flow [v] = min (cap,flow [u]); pre [v] = ptr; if (!inq [v]) { inq [v] = true; q.push (v); } } } } if (!pre [t]) { return 0; } int x = t; while (x != s) { datas [pre [x]].cap -= flow [t]; datas [pre [x]^1].cap += flow [t]; cost += flow [t] * datas [pre [x]].price; x = datas [pre [x]].u; } return flow [t]; } int main () { #ifndef ONLINE_JUDGE freopen ("shit.txt","r",stdin); #endif ios::sync_with_stdio (false); cin >> n >> m; s = n + 1,t = n; for (int i = 1;i <= m;++ i) { int u,v,d;cin >> u >> v >> d; add (n + u,v,1,d); add (v,n + u,0,-d); } for (int i = 2;i < n;++ i) { add (i,n + i,1,0); add (n + i,i,0,0); } int ans = 0,rt; while (rt = bfs ()) ans += rt; cout << ans << " " << cost << endl; return 0; } ```
by Dorbmon @ 2020-01-17 17:00:56


|