2015 Multi-University Training Contest 5 hdu 5348 MZL's endless loop
MZL's endless loop
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1853 Accepted Submission(s): 400
Special Judge
You are given an undirected graph with n vertexs and m edges. Please direct all the edges so that for every vertex in the graph the inequation |out degree − in degree|≤1 is satisified.
The graph you are given maybe contains self loops or multiple edges.
For each test case, the first line contains two integers n and m.
And the next m lines, each line contains two integers ui and vi, which describe an edge of the graph.
T≤100, 1≤n≤105, 1≤m≤3∗105, ∑n≤2∗105, ∑m≤7∗105.
In ith line contains a integer 1 or 0, 1 for direct the ith edge to ui→vi, 0 for ui←vi.
解题:欧拉回路+欧拉路径,开始还以为是混合图的欧拉回路呢。。。哎。。。注意爆栈。。。
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
struct arc {
int to,next;
bool vis;
arc(int x = ,int y = -) {
to = x;
next = y;
vis = false;
}
} e[];
int head[],d[maxn],tot,n,m;
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
bool dfs(int u) {
for(int &i = head[u]; ~i; i = e[i].next) {
if(e[i].vis || e[i^].vis) continue;
e[i].vis = true;
if(d[e[i].to]) {
d[e[i].to] = ;
return true;
}
if(dfs(e[i].to)) return true;
}
return false;
}
void cao() {
for(int i = ; i <= n; ++i)
if(d[i]) {
d[i] = ;
dfs(i);
}
for(int i = ; i <= n; ++i)
while(~head[i]) dfs(i);
}
int main() {
int kase,u,v;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&m);
memset(head,-,sizeof head);
for(int i = tot = ; i < m; ++i){
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
d[u] ^= ;
d[v] ^= ;
}
cao();
for(int i = ; i < tot; i += )
printf("%d\n",e[i].vis);
}
return ;
}
2015 Multi-University Training Contest 5 hdu 5348 MZL's endless loop的更多相关文章
- Hdu 5348 MZL's endless loop (dfs)
题目链接: Hdu 5348 MZL's endless loop 题目描述: 给出一个无向图(有环,有重边),包含n个顶点,m条边,问能否给m条边指定方向,使每个顶点都满足abs(出度-入度)< ...
- HDU 5348 MZL's endless loop(DFS去奇数度点+欧拉回路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题目大意:给你一张图,有n个点,和m条无向边,让你把m条无向边变成有向边,使得每个节点的|出度- ...
- HDU 5348 MZL's endless loop 给边定向(欧拉回路,最大流)
题意: 给一个所有你可能想得到的奇葩无向图,要求给每条边定向,使得每个点的入度与出度之差不超过1.输出1表示定向往右,输出0表示定向往左. 思路: 网络流也是可以解决的!!应该挺简单理解的.但是由于复 ...
- HDU 5348 MZL's endless loop
乱搞题...第一直觉是混合图的欧拉通路,但是感觉并没有多大关系.最终AC的做法是不断的寻找欧拉通路,然后给边标号.所有边访问了一遍,所有点访问了一遍,效率是o(n+m).不存在-1的情况. #incl ...
- 图论 HDOJ 5348 MZL's endless loop
题目传送门 /* 题意:给一个n个点,m条边的无向图,要求给m条边定方向,使得每个定点的出入度之差的绝对值小于等于1. 输出任意一种结果 图论:一个图,必定存在偶数个奇度顶点.那么从一个奇度定点深搜, ...
- 2015 Multi-University Training Contest 5 hdu 5352 MZL's City
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem
MZL's simple problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
随机推荐
- applicationContext-solr.xml
一.动态切换单机和集群 spring-solr 的配置 <!-- 单机版 solrj --> <bean id = "httpSolrServer" class= ...
- 对Java线程安全与不安全的理解
当我们查看JDK API的时候,总会发现一些类说明写着,线程安全或者线程不安全,比如说到StringBuilder中,有这么一句,"将StringBuilder 的实例用于多个线程是不安全的 ...
- 洛谷 P1270 “访问”美术馆(树形DP)
P1270 “访问”美术馆 题目描述 经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动.艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室.Peer ...
- [Beginning SharePoint Designer 2010]Chapter2 编辑页面
本章概要: 1.如何展开隐藏任务面板和ribbon标签 2.页面编辑模式 3.代码视图模式和智能提示 4.如何组合SharePoint和页面上其他元素
- 使用UE4公布安卓平台游戏
使用了几天的UE4 ,总算是将游戏在安卓平台执行起来了.当中遇到非常多问题,而且终于依旧有一些问题没能解决. 整体感觉是UE4这款引擎眼下还不够成熟.问题较多. 没有unity使用起来方便. 可是既然 ...
- 【前端福利】用grunt搭建自己主动化的web前端开发环境-完整教程
jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发者.假设你如今还不知道grunt或者听说过. ...
- winform显示系统托盘,双击图片图表显示窗体,退出窗体是否提示
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult result = Messag ...
- MongoDB 2.6安装
Workaround to install as a service You can manually install 2.6.0 as a service on Windows from an Ad ...
- DBS-MySQL:MYSQL获取自增ID的四种方法
ylbtech-DBS-MySQL:MYSQL获取自增ID的四种方法 1.返回顶部 1. 1. select max(id) from tablename 2.SELECT LAST_INSERT_I ...
- python黏包解决方案
解决方案 # 我们可以借助一个模块,这个模块可以把要发送的数据长度转换成固定长度的字节.这样客户端每次接 # 收消息之前只要先接受这个固定长度字节的内容看一看接下来要接收的信息大小,那么最终接受的数据 ...