URAL 1176 Hyperchannels(欧拉回路路径)
Hyperchannels
Memory limit: 64 MB
Galaxy Empire consists of N planets. Hyperchannels exist between most
of the planets. New Emperor urged to extend hyperchannels network in
such a way, that he can move from any planet to any other using no more
than one channel. One can pass through the channel only in one
direction.
last channel-establishing ship is located on the base near planet A.
This ship can’t pass through the existing channel, it always establishes
a new one. But presence of two channels connecting the same planets in
one direction makes navigation too difficult, almost impossible. The
problem is to find a route for this ship to establish all necessary
channels with no excessive ones. In the end of this route ship should
return to the base.
Input
Each of the following N lines contain N numbers, the j-th number of the i-th line equals to 1 if there exists channel from planet i to planet j, and equals to 0 otherwise.
It is known, that Empire can fulfill its need of hyperchannels by establishing no more than 32000 new ones.
Output
should contain the sequence in which channels should be established.
Each line should contain two integers — numbers of source and
destination planet of channel. You may assume, that solution always
exists.
Sample
input | output |
---|---|
4 2 |
2 4 |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int n,m,cnt=;
int tot=,s,t;
int head[N],dis[N],vis[N][N],pre[N];
int in[N],out[N];
stack<int>st;
struct man {
int to,next;
} edg[N*N];
void add(int u,int v) {
edg[tot].to=v;
edg[tot].next=head[u];
head[u]=tot++;
}
void dfs(int u){
for(int i=head[u];i!=-;i=edg[i].next){
int v=edg[i].to;
if(!vis[u][v]){
vis[u][v]=;
dfs(v);
}
}
st.push(u);
}
int main() {
int u,v,nn=,sum=;
met(head,-);
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&u);
if(!u&&i!=j)add(i,j);
}
}
dfs(s);
u=st.top();st.pop();
while(!st.empty()){
v=st.top();
st.pop();
printf("%d %d\n",u,v);
u=v;
}
return ;
}
URAL 1176 Hyperchannels(欧拉回路路径)的更多相关文章
- UOJ 117 欧拉回路(套圈法+欧拉回路路径输出+骚操作)
题目链接:http://uoj.ac/problem/117 题目大意: 解题思路:先判断度数: 若G为有向图,欧拉回路的点的出度等于入度. 若G为无向图,欧拉回路的点的度数位偶数. 然后判断连通性, ...
- URAL 1137 Bus Routes(欧拉回路路径)
1137. Bus Routes Time limit: 1.0 secondMemory limit: 64 MB Several bus routes were in the city of Fi ...
- 1176. Hyperchannels(欧拉回路)
1176 给定一有向图 求其反图的欧拉回路 路径输反了 一直WA.. #include <iostream> #include<cstdio> #include<cstr ...
- UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)
题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...
- 欧拉图 欧拉回路 欧拉通路 Euler
欧拉图 本文链接:http://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回 ...
- 欧拉图 欧拉回路 欧拉通路 Euler的认识 (转)
转:https://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回路的图称为欧 ...
- 「LuoguP1341」 无序字母对(欧拉回路
题目描述 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造一个有n+1个字母的字符串使得每个字母对都在这个字符串中出现. 输入输出格式 输入格式: 第一行输入一 ...
- Ural 1635 Mnemonics and Palindromes(DP)
题目地址:space=1&num=1635">Ural 1635 又是输出路径的DP...连着做了好多个了. . 状态转移还是挺简单的.要先预处理出来全部的回文串,tag[i] ...
- hdu 3472 HS BDC(混合路的欧拉路径)
这题是混合路的欧拉路径问题. 1.判断图的连通性,若不连通,无解. 2.给无向边任意定向,计算每个结点入度和出度之差deg[i].deg[i]为奇数的结点个数只能是0个或2个,否则肯定无解. 3.(若 ...
随机推荐
- Linux面试基础题-2
继续我们这面试系列,在这篇文章里我们给出了10个问题.这些问题或者是在以后的文章中出现的问题不一定在面试中会被问到.然而通过这些文章我们呈现出的是一个交互的学习平台,这必将会对你有很大的帮助. 自本系 ...
- 对项目的测试--Resharper
初学 这里做个记录. 1:安装后,Resharper会用他自己的英文智能提示,替换掉 vs2010的智能提示,所以我们要换回到vs2010的智能提示 2:快捷键.是使用vs2010的快捷键还是使用 R ...
- SharePoint 2013 开发——APP开发的考虑和建议
博客地址:http://blog.csdn.net/FoxDave 需要考虑的方面: 1. 记得CSOM授予网站集及以下的权限,而场解决方案需要整个场的访问权限. 2. 由于应用程序是彼此完全独立 ...
- Oracle GoldenGate 12c实时捕获SQL Server数据
在Oracle GoldenGate 12c中,对一些最新的数据库提供了支持,比如SQL Server 2012/2014,当然12c也支持sql server 2008.主要新增特性有: 捕获进程可 ...
- STM32串口USART1的使用方法
前言: 通用同步异步收发器(USART)提供了一种灵活的方法来与使用工业标准NR 异步串行数据格式的外部设备之间进行全双工数据交换. USART利用分数波特率发生器提供宽范围的 波特率选择,支持同 ...
- Stm32_调试出现 Error:Flash Download Failed-"Cortex-M3"
rror:Flash Download Failed-"Cortex-M3"出现一般有两种情况: 1.SWD模式下,Debug菜单中,Reset菜单选项(Autodetect/HW ...
- 实用的WPF Xml的简易读写类以及用法示例
转自:http://www.silverlightchina.net/html/study/WPF/2012/0808/17980.html 最近真是写博客写的不可收拾,今天再来一篇. 因为做一些程序 ...
- 重拾java系列一java基础(2)
1.分支流程控制 if(布尔表达式/分支条件){ //语句块} if(布尔表达式/分支条件){ //语句块1}else{ //语句块2} if(条件1){ //语句块1}else if(条件2 ...
- Mac commands
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java uname -a 显示系统隐藏文件.在终端(Ter ...
- 模拟http或https请求,实现ssl下的bugzilla登录、新增BUG,保持会话以及处理token
1.增加相应httpclient 需要的jar包到工程,如果是maven工程请在pom.xml增加以下配置即可: <dependency> <groupId>org.apach ...