HDOJ 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): 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 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.
 

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 integers  n  and  m .
And the next  m  lines, each line contains two integers  ui  and  vi , which describe an edge of the graph.
T100 1n105 1m3105 n2105 m7105 .
 

Output
For each test case, if there is no solution, print a single line with  1 , otherwise output  m  lines,.
In  i th line contains a integer  1  or  0 1  for direct the  i th edge to  uivi 0  for  uivi .
 

Sample Input
  
2 3 3 1 2 2 3 3 1 7 6 1 2 1 3 1 4 1 5 1 6 1 7
 

Sample Output
  
1 1 1 0 1 0 1 0 1
 

Source
 

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);
				else
					dfs(i, 1);
			}
		}

		for (int i = 0; i < edge_cnt; i += 2)
			printf("%d\n", edge[i].dict);
	}

	return 0;
}



资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值