网络流/最大流


  愚人节快乐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. CKeditor的简单使用

    由于项目中要使用ckeditor 做个推荐功能,由于值设定到文本内容,就选择最基本的使用. 使用的版本为当前最新版本4.4.7,你需要下载两部分,一个是前台使用,一个是后台使用, 你可以到我的网盘中下 ...

  2. reader,字符流

    1. public class Demo1 { public static void main(String[] args) throws IOException { File file = new ...

  3. 决策树的基本ID3算法

    一  ID3算法的大致思想 基本的ID3算法是通过自顶向下构造决策树来进行学习的.我们首先思考的是树的构造从哪里开始,这就涉及到选择属性进行树的构造了,那么怎样选择属性呢?为了解决这个问题,我们使用统 ...

  4. autolayout 总结

    hasAmbiguousLayoutexerciseAmbiguityInLayout_autolayoutTracerecursiveDescription 第一步:更新约束,可以被认为是一个“计量 ...

  5. sftp

    SFTP 为 SSH的一部分,是一种传输档案至 Blogger 伺服器的安全方式.其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文 ...

  6. 窗体皮肤实现 - 实现简单Toolbar(六)

    自定义皮肤很方便,基础开发的工作也是很大的.不过还好一般产品真正需要开发的并不是很多.现在比较漂亮的界面产品都会有个大大的工具条. Toolbar工具条实现皮肤的方法还是可以使用Form的处理方案.每 ...

  7. 常用的PC/SC接口函数

    PC/SC规范是一个基于WINDOWS平台的一个标准用户接口(API),提供了一个从个人电脑(Personal Computer)到智能卡(SmartCard)的整合环境,PC/SC规范建立在工业标准 ...

  8. Mysql数据库基本配置

    一 数据库基本配置包括编码方式 (安装环境是在linux下) 1.1 进入数据库 开启数据库服务:service mysqld start/restart(如果开启话可以重启) 关闭数据库服务:ser ...

  9. eclipse java.lang.OutOfMemoryError: Java heap space

    1.手动编译运行需要添加 java -Xms256m -Xmx1024m classname 2.在eclipse中,在run as -> run configurations -> ar ...

  10. NFC应用实例

    package com.example.mynfcdemon; import android.app.Activity;import android.nfc.NfcAdapter;import and ...