文章
3
粉丝
260
获赞
9
访问
36.6k
 
这道题是我在本站上A的第一道题,那我们直接开始吧:
首先,我们要用到转换的思想,既然这道题跟代数有关,那我们便可以把它转换为图论,如图:

又因为在题目的数据中并没有负数,那么,显然这个问题就转化为了求源点S到汇点T的最大流,接着就是模板就行了
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int getint() {
    int ret=0,flag=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')flag=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0') {
        ret=(ret<<3)+(ret<<1)+c-'0';
        c=getchar();
    }
    return ret*flag;
}
int n,m;
int S,T;
int cnt,head[100005];
struct edge {
    int ne,v,w,pair;
} e[2000005];
void add(int u,int v,int p) {
    cnt++;
    e[cnt].v=v;
    e[cnt].w=p;
    e[cnt].pair=cnt+1;
    e[cnt].ne=head[u];
    head[u]=cnt;
//    cnt++;
//    e[cnt].v=u;
//    e[cnt].w=0;
//    e[cnt].pair=cnt-1;
//    e[cnt].ne=head[v];
//    head[v]=cnt;
}
int dis[100005],gap[100005];
int DFS(int x,int maxf) {
    if(x==T)return maxf;
    int ret=0;
    for(int i=head[x]; i...
    
登录后发布评论
真是疯了
大佬花式解题,给跪了!!!
疯了????
请问模版是在哪里总结的