题意:给一幅图,从1开始,每条边有边权最少走一遍,可以在任意点退出,问最小花费
题解:上下界费用流,每个边都流一遍,然后为了保证流量平衡,新建源点汇点,跑费用流把流量平衡/************************************************************** Problem: 3876 User: walfy Language: C++ Result: Accepted Time:140 ms Memory:2868 kb****************************************************************/ //#pragma GCC optimize(2)//#pragma GCC optimize(3)//#pragma GCC optimize(4)//#pragma GCC optimize("unroll-loops")//#pragma comment(linker, "/stack:200000000")//#pragma GCC optimize("Ofast,no-stack-protector")//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")#include#define fi first#define se second#define db double#define mp make_pair#define pb push_back#define pi acos(-1.0)#define ll long long#define vi vector #define mod 1000000009#define ld long double//#define C 0.5772156649#define ls l,m,rt<<1#define rs m+1,r,rt<<1|1#define pll pair #define pil pair #define pli pair #define pii pair #define ull unsigned long long//#define base 1000000000000000000#define fin freopen("a.txt","r",stdin)#define fout freopen("a.txt","w",stdout)#define fio ios::sync_with_stdio(false);cin.tie(0)inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}template inline T const& MAX(T const &a,T const &b){return a>b?a:b;}template inline T const& MIN(T const &a,T const &b){return a >=1;}return ans;}inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const ull ba=233;const db eps=1e-5;const ll INF=0x3f3f3f3f3f3f3f3f;const int N=500+10,maxn=100000+10,inf=0x3f3f3f3f; bool vis[N];int cnt,head[N],pre[N],path[N],dis[N],in[N],out[N];struct edge{int to,Next,c,cost;}e[maxn];void init(){memset(head,-1,sizeof head);cnt=0;}void add(int u,int v,int c,int cost){// printf("%d %d %d %lld\n",u,v,c,cost); e[cnt].to=v;e[cnt].c=c;e[cnt].cost=cost;e[cnt].Next=head[u];head[u]=cnt++; e[cnt].to=u;e[cnt].c=0;e[cnt].cost=-cost;e[cnt].Next=head[v];head[v]=cnt++;}bool spfa(int s,int t){ memset(pre,-1,sizeof pre); memset(dis,inf,sizeof dis); memset(vis,0,sizeof vis); dis[s]=0;vis[s]=1; queue q;q.push(s); while(!q.empty()) { int x=q.front();q.pop(); vis[x]=0; for(int i=head[x];~i;i=e[i].Next) { int te=e[i].to; if(e[i].c>0&&dis[x]+e[i].cost out[i])add(ss,i,in[i]-out[i],0); else add(i,tt,out[i]-in[i],0); } ans+=mincostmaxflow(ss,tt); printf("%d\n",ans); return 0;}/********************62 2 1 3 22 4 3 5 42 5 5 6 6000********************/