Bare Cost Stream ... Split, flow limit is 1, final traffic and cost is the answer.
----------------------------------------------------------------------
#include <bits/stdc++.h>using namespace std;const int MAXN = 409;const int INF = 1 <<;struct Edge {int to, cap, cost;Edge *next, *rev;} e[50000], *pt = E, *HEAD[MAXN];inline void Add (int u, int v, int d, int w) {pt->to = v; pt->cap = D;pt->cost = w; pt->next = Head[u];Head[u] = pt++;}inline void Addedge (int u, int v, int d, int w) {Add (U, V, D, W); Add (V, u, 0,-W);Head[u]->rev = head[v];Head[v]->rev = Head[u];}bool INQ[MAXN];queue<int> Q;int D[MAXN], A[MAXN], FLOW, cost, N, S, T;edge* P[MAXN];void Mincost () {FLOW = Cost = 0;for (;;) {for (int i = 0; i < N; i++) {Inq[i] = false;D[i] = INF;}Q.push (S); D[s] = 0; A[s] = INF;While (! Q.empty ()) {int x = Q.front (); Q.pop ();Inq[x] = false;For (edge* e = head[x]; e; e = e->next) if (e->cap && d[e->to] > d[x] + e->cost) {D[e->to] = d[x] + e->cost;A[e->to] = min (E->cap, a[x]);P[e->to] = e;if (!inq[e->to])Inq[e->to] = True, Q.push (e->to);}}if (d[t] = = INF) break;FLOW + = a[t];Cost + = a[t] * D[t];for (int x = T; x! = S; x = p[x]->rev->to) {P[x]->cap-= a[t];P[x]->rev->cap + = a[t];}}}#define OUT (i) ((i) + n-1)int main () {int n, m;cin >> n >> m;N = (n-1) << 1; S = 0; T = n-1;for (int i = 1; i < n-1; i++)Addedge (I, Out (i), 1, 0);While (m--) {int U, V, W;scanf ("%d%d%d", &u, &v, &w); --u;--v;if (u) u = out (u);Addedge (U, V, 1, W);}mincost ();printf ("%d%d\n", FLOW, cost);return 0;}
-----------------------------------------------------------------------
1877: [SDOI2009] Morning Run Time Limit:4 Sec Memory Limit:MB
Submit:1420 Solved:743
[Submit] [Status] [Discuss] Descriptionelaxia recently had a crush on karate, and he set up a fitness program for himself, such as push-ups, sit-ups and so on, but so far, he has only survived the morning run. Now give a map near the school, which contains n intersections and M streets, Elaxia can only run from one intersection to another, and the streets intersect only at intersections. Elaxia every day from the dormitory run to school, to ensure that the dormitory number 1, the school number is n. Elaxia's morning running plan is carried out by cycle (including several days), because he does not like to follow the repeated route, so in a cycle, the daily morning running route will not intersect (at the crossroads), bedroom and school is not a crossroads. Elaxia stamina is not very good, he hopes to run in a cycle as short as possible, but also want the training cycle to contain as long as possible. In addition to practicing karate, Elaxia other time spent studying and looking for mm above, all he would like to ask you to help him design a suit to meet his requirements of the morning run plan. Input first line: two number n,m. Indicates the number of intersections and streets. The next M-line, 3 numbers per line, indicates that there is a street (unidirectional) with a length of c between junction A and intersection B (a,b,c). Output two digits, the first number is the longest period of the number of days, the second number is the shortest length of travel to meet the maximum number of days. Sample Input 7 10
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
4 6 1
2 5 5
3 6 6
5 7 1
6 7 1Sample Output 2HINT
For 30% of data, n≤20,m≤120.
For 100% of data, n≤200,m≤20000.
Source
Day1
Bzoj 1877: [SDOI2009] morning run (minimum cost maximum flow)