首页 > 代码库 > codeforces 269C Flawed Flow

codeforces 269C Flawed Flow

没什么要注意的。。。n别入队就行了。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#define maxv 200500#define maxe 400500using namespace std;int n,m,nume=1,g[maxv],d[maxv],t[maxv],x,y,z;bool vis[maxv];queue <int> q;struct edge{    int v,w,flag,nxt;}e[maxe];void addedge(int u,int v,int w){    e[++nume].v=v;    e[nume].w=w;    e[nume].nxt=g[u];    e[nume].flag=0;    g[u]=nume;}void bfs(){    q.push(1);vis[1]=true;    while (!q.empty())    {        int head=q.front();q.pop();        for (int i=g[head];i;i=e[i].nxt)        {            int v=e[i].v;            if (vis[v]) continue;            e[i].flag=1;t[v]-=e[i].w;            if ((t[v]==d[v]/2) && (v!=n)) {vis[v]=true;q.push(v);}        }    }}int main(){    scanf("%d%d",&n,&m);    for (int i=1;i<=m;i++)    {        scanf("%d%d%d",&x,&y,&z);        addedge(x,y,z);addedge(y,x,z);        d[x]+=z;d[y]+=z;    }    for (int i=1;i<=n;i++) t[i]=d[i];    bfs();    for (int i=2;i<=nume;i+=2)    {        if (e[i].flag) printf("0\n");        else printf("1\n");    }    return 0;}

 

codeforces 269C Flawed Flow