网络流/最大流


  愚人节快乐XD

  这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路……

  我们知道如果一个【连通】图中每个节点都满足【入度=出度】那么就一定有欧拉回路……

  那么每条边都可以贡献一个出度出来,对于一条边u->v:

    连S->edge cap=1;

    如果是有向边,就连 edge->v cap=1;

    否则(无向边)连edge->u cap=1, edge->v cap=1;

  然后每个点的总度数我们是知道的……那么它最后的【出度】就等于 总度数/2。(这个地方我傻逼了没想到……

  P.S.这题是跟POJ2699比较类似的

 Source Code
Problem: User: sdfzyhy
Memory: 1148K Time: 32MS
Language: G++ Result: Accepted Source Code //BZOJ 1000
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std; int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
return v*sign;
}
typedef long long LL;
const int N=,M=,INF=~0u>>;
/*******************tamplate********************/
int n,m,ans,du[];
struct edge{int to,v;};
struct Net{
edge E[M];
int next[M],head[N],cnt;
void ins(int x,int y,int z){E[++cnt]=(edge){y,z};next[cnt]=head[x];head[x]=cnt;}
void add(int x,int y,int z){ins(x,y,z); ins(y,x,);}
int S,T,d[N],Q[M],cur[N];
bool mklevel(){
F(i,,T) d[i]=-;
int l=,r=-;
Q[++r]=S; d[S]=;
while(l<=r){
int x=Q[l++];
for(int i=head[x];i;i=next[i])
if(E[i].v && d[E[i].to]==-){
d[E[i].to]=d[x]+;
Q[++r]=E[i].to;
}
}
return d[T]!=-;
}
int dfs(int x,int a){
if(x==T)return a;
int flow=;
for(int &i=cur[x];i && flow<a;i=next[i])
if(E[i].v && d[E[i].to]==d[x]+){
int f=dfs(E[i].to,min(a-flow,E[i].v));
E[i].v-=f;
E[i^].v+=f;
flow+=f;
}
if(!flow) d[x]=-;
return flow;
}
void Dinic(){
while(mklevel()){
F(i,S,T) cur[i]=head[i];
ans+=dfs(S,INF);
}
}
void init(){
n=getint(); m=getint();
cnt=; memset(head,,sizeof head);
F(i,,n) du[i]=;
S=; T=n+m+; ans=;
int x,y,z;
F(i,,m){
x=getint(); y=getint(); z=getint();
add(S,i,); add(i,y+m,);
if (!z) add(i,x+m,);
du[x]++; du[y]++;
}
F(i,,n){
if (du[i]%){puts("impossible");return;}
add(i+m,T,du[i]/);
}
Dinic();
if (ans==m) puts("possible");
else puts("impossible");
}
}G1;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int T=getint();
while(T--) G1.init();
return ;
}

【POJ】【1637】Sightseeing tour的更多相关文章

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

  10. Sightseeing tour 【混合图欧拉回路】

    题目链接:http://poj.org/problem?id=1637 Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total ...

随机推荐

  1. Asp.net页面跳转Session丢失问题

    原本去年在做项目时,写好的一记篇博客分享给大家. Asp.net页面跳转Session丢失问题   编写人:CC阿爸 2014-4-2 l  近来在做泛微OA与公司自行开发的系统集成登录的问题.在使用 ...

  2. SQL中补0

     SQL中补0 编写人:CC阿爸 2014-3-14 第一种方法: right('00000'+cast(@count as varchar),5) 其中'00000'的个数为right函数的最后参数 ...

  3. 利用脚本修改SQL SERVER排序规则

    利用脚本修改SQL SERVER排序规则 编写人:CC阿爸 2014-3-1 l  今年的一项重要工作是对公司所用系统进行繁简的转换,程序转成简体基本很容易解决,但数据库转换成简体,就没那么容易了.经 ...

  4. linux安装至少有哪两个分区,各自作用是什么?

    1.至少有/代表根分区,/swap代表的意思是交换分区. 2.swap相当于缓存的作用:

  5. delphi的几个特别关键字 object absolute

    1.object关键字相当于C++中的struct, record定义个结构体只能定义数据,而object可以定义方法,默认都是public的.   代码示例如下: TTest = record na ...

  6. ruby on rails 实战(一)

    通过ruby on rails 一步一步搭建个人站点,涉及到的技术有:ruby,rails,javascript,jquery 操作系统:win7 IDE: rubymine 5.4. 第一步,下载安 ...

  7. openSUSE13.1 Yast 中所有软件图形化界面无法打开,问题原因: Ruby

    因为使用rvm安装了新的Ruby,而openSUSE13.1的YaST又是用Ruby的.....解决方案暂时没有

  8. C# 将汉字转化成拼音

    本文来自http://www.cnblogs.com/yazdao/archive/2011/06/04/2072488.html 首先下载Visual Studio International Pa ...

  9. hdu 1029

    #include"stdio.h" int main(void) { int n,x,y,t,i; while(scanf("%d",&n)!=EOF) ...

  10. SQL1092N The requested command or operation failed because the user ID does not have the authority to perform the requested command or operation.

    1.前一天安装号db2后,做了如下处理: ************************************************************ 修改 /etc/sudoers 文件 ...