HDOJ 5348 MZL's endless loop
来源:互联网 发布:中国印度边境冲突 知乎 编辑:程序博客网 时间:2024/06/06 01:20
MZL's endless loop
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2043 Accepted Submission(s): 442
Special Judge
Problem Description
As we all kown, MZL hates the endless loop deeply, and he commands you to solve this problem to end the loop.
You are given an undirected graph withn 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.
You are given an undirected graph with
The graph you are given maybe contains self loops or multiple edges.
Input
The first line of the input is a single integer T , indicating the number of testcases.
For each test case, the first line contains two integersn and m .
And the nextm 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 .
For each test case, the first line contains two integers
And the next
Output
For each test case, if there is no solution, print a single line with −1 , otherwise output m lines,.
Ini th line contains a integer 1 or 0 , 1 for direct the i th edge to ui→vi , 0 for ui←vi .
In
Sample Input
23 31 22 33 17 61 21 31 41 51 61 7
Sample Output
111010101
Source
2015 Multi-University Training Contest 5
Recommend
wange2014
#include <cstdio>#include <cstring>const int N = 1e5 + 10;int degree[N];int targ[N][2];int head[N];bool vis[N];int edge_cnt, found;struct node{int v, next, dict;}edge[N * 6];void Init() {memset(head, -1, sizeof(head));memset(vis, false, sizeof(vis));memset(targ, 0, sizeof(targ));memset(degree, 0, sizeof(degree));edge_cnt = 0;}void add_edge(int u, int v) {node tmp = {v, head[u], -1};head[u] = edge_cnt;edge[edge_cnt++] = tmp;}void dfs(int u, int dict) {if (vis[u] == true) {found = u;return ;}vis[u] = true;while (~head[u]) {int lct = head[u];node tmp = edge[lct];head[u] = tmp.next;int v = tmp.v;if (edge[lct].dict != -1 || (u != v && targ[v][dict ^ 1] > targ[v][dict]))continue;edge[lct].dict = dict;edge[lct ^ 1].dict = dict ^ 1;targ[u][dict]++;targ[v][dict ^ 1]++;dfs(v, dict);if (found != -1) {if (found == u) {found = -1;continue;}else {vis[u] = false;break;}}break;}vis[u] = false;}int main() {int T;scanf("%d", &T);while (T--) {Init();int n, m;int u, v;scanf("%d%d", &n, &m);for (int i = 0; i < m; ++i) {scanf("%d%d", &u, &v);degree[u]++;degree[v]++;add_edge(u, v);add_edge(v, u);}for (int i = 1; i <= n; ++i) {while (targ[i][0] + targ[i][1] < degree[i]) {found = -1;if (targ[i][0] <= targ[i][1])dfs(i, 0);elsedfs(i, 1);}}for (int i = 0; i < edge_cnt; i += 2)printf("%d\n", edge[i].dict);}return 0;}
0 0
- HDOJ 5348 MZL's endless loop 乱搞
- HDOJ 5348 MZL's endless loop
- hdu 5348 MZL's endless loop
- HDU 5348 MZL's endless loop
- *HDU 5348 - MZL's endless loop(搜索)
- hdu 5348 MZL's endless loop
- hdu 5348 MZL's endless loop 暴搜
- hdu 5348 MZL's endless loop dfs
- Hdu 5348 MZL's endless loop (构造)
- hdu 5348 MZL's endless loop(dfs+图论)
- hdu 5348 MZL's endless loop(dfs)
- hdu 5348 MZL's endless loop 欧拉回路
- HDU 5348 MZL's endless loop(DFS+邻接表)
- HDU 5348 MZL's endless loop (dfs+删边)
- HDU5348 MZL's endless loop (搜索)
- 图论 - hdu5348 MZL's endless loop
- hdu 5348 MZL's endless loop(欧拉路径+欧拉环)
- HDU 5348 MZL's endless loop(思想用的是深搜)经典
- java 深入解析FileInputStream和FileOutputStream
- java 序列化与反序列化
- 杭电 2087 剪花布条 kmp水题
- c++/c中流的概念
- UVa 10806 Dijkstra, Dijkstra (无向图+最小费用最大流+最短路:)
- HDOJ 5348 MZL's endless loop
- hdu4124
- Linux - test测试标志的意思总结
- HDUOJ 又一版A+B 题目1877
- 倒油问题,广度优化搜索,java
- poj 2195 Going Home【最小费用最大流】
- IOS 自定义滑动Tab(顶部) 带滑动的条条
- 数据库锁
- IO学习