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: ...
随机推荐
- JavaScript(DOM编程三)
节点的移动,insertBefore <body> <p>你喜欢哪个城市?</p> <ul id="city"><li id= ...
- asp.net mvc-identity初步学习
Install-Package Microsoft.AspNet.Identity.EntityFramework Install-Package Microsoft.AspNet.Identity. ...
- R语言基础-数组和列表
数组(array) 一维数据是向量,二维数据是矩阵,数组是向量和矩阵的直接推广,是由三维或三维以上的数据构成的. 数组函数是array(),语法是:array(dadta, dim),当中data必须 ...
- Autodesk 举办的 Revit 2015 二次开发速成( 1.5 天),教室培训, 地点武汉
2014年8月26日9:00 – 17:00 2014年8月27日9:00 – 12:00 培训地点: Ø 湖北工业大学 实训楼605教室 Ø 地址:武汉市武昌区南湖李家墩一村一号 Ø 交通路线说明: ...
- 使用CNN做文本分类——将图像2维卷积换成1维
使用CNN做文本分类 from __future__ import division, print_function, absolute_import import tensorflow as tf ...
- Laravel异常处理
Laravel异常处理 标签(空格分隔): php 自定义异常类 <?php namespace App\Exceptions; use Throwable; use Exception; cl ...
- 12. Integer to Roman[M]整数转罗马数字
题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...
- Linux中安装redis的phpredis扩展
下载phpredis扩展 http://pecl.php.net/package/redis wget http://pecl.php.net/get/redis-4.0.2.tgz 需要环境配置文件 ...
- python爬虫:爬取医药数据库drugbank
这个是帮朋友做的,难点就是他们有一个反爬虫机制,用request一直不行,后面我就用selenium直接把网页copy下来,然后再来解析本地的html文件,就木有问题啦. 现在看来,写得有点傻,多包涵 ...
- 指定的WSDL可能与所选的工具包不兼容
使用LoadRunner在webservice协议下,import service的时候,报错: can not fetch WSDL,the specified WSDL datathe speci ...