Hyperchannels

Time limit: 1.0 second
Memory limit: 64 MB
The
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.
The
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

First line contains integer N ≤ 1000 and number of the planet A (AN) where the base is situated.
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

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
0 0 1 0
0 0 1 0
1 1 0 1
0 0 1 0
2 4
4 1
1 2
2 1
1 4
4 2
Problem Author: Pavel Atnashev
#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(欧拉回路路径)的更多相关文章

  1. UOJ 117 欧拉回路(套圈法+欧拉回路路径输出+骚操作)

    题目链接:http://uoj.ac/problem/117 题目大意: 解题思路:先判断度数: 若G为有向图,欧拉回路的点的出度等于入度. 若G为无向图,欧拉回路的点的度数位偶数. 然后判断连通性, ...

  2. URAL 1137 Bus Routes(欧拉回路路径)

    1137. Bus Routes Time limit: 1.0 secondMemory limit: 64 MB Several bus routes were in the city of Fi ...

  3. 1176. Hyperchannels(欧拉回路)

    1176 给定一有向图 求其反图的欧拉回路 路径输反了 一直WA.. #include <iostream> #include<cstdio> #include<cstr ...

  4. UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)

    题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...

  5. 欧拉图 欧拉回路 欧拉通路 Euler

    欧拉图 本文链接:http://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回 ...

  6. 欧拉图 欧拉回路 欧拉通路 Euler的认识 (转)

    转:https://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回路的图称为欧 ...

  7. 「LuoguP1341」 无序字母对(欧拉回路

    题目描述 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造一个有n+1个字母的字符串使得每个字母对都在这个字符串中出现. 输入输出格式 输入格式: 第一行输入一 ...

  8. Ural 1635 Mnemonics and Palindromes(DP)

    题目地址:space=1&num=1635">Ural 1635 又是输出路径的DP...连着做了好多个了. . 状态转移还是挺简单的.要先预处理出来全部的回文串,tag[i] ...

  9. hdu 3472 HS BDC(混合路的欧拉路径)

    这题是混合路的欧拉路径问题. 1.判断图的连通性,若不连通,无解. 2.给无向边任意定向,计算每个结点入度和出度之差deg[i].deg[i]为奇数的结点个数只能是0个或2个,否则肯定无解. 3.(若 ...

随机推荐

  1. MonoRail学习-入门实例篇

    1.到官方网站下载安装文件,地址如下: http://www.castleproject.org/index.php/Castle:Download目前最新版本Beta5(您也可以不需要下载,直接使用 ...

  2. C/C++中函数参数传递详解(一)

    *在定义时使用代表指针类型,其他情况代表取内容.&在定义时使用代表引用(别名),在其他情况代表取地址 在编写个人函数的时候,你将会受到C++中的一条基本的原则的限制:在默认的情况下,变量只能以 ...

  3. MyQQ 前言

    从接触IOS以来也将近8个月了,学习了不少知识. 看了一系列的书籍如: <objective-c 开发入门>--语法介绍,学习一门语言是开发的基础.所以这是我大致对语法语句学习的锻炼地方, ...

  4. 数组的foreach方法和jQuery中的each方法

    /* * 数组的forEach方法: * 1.返回给回调的参数先是值,然后是下标 * 2.回调函数执行时内部的this指向window * */ /*var arr = [1,2,3,4,5]; ar ...

  5. iframe和form表单的target应用简单例子

    iframe和form表单的target属性   Problem: 刷新主页面中的其中一个iframe,其他内容不变 Solution: main.jsp <body onload=" ...

  6. Oracle数据库DECODE函数的使用.

    decode函数是Oracle数据库独有的. 语法为: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 例子:select decode(sign(变量1-变量2) ...

  7. Apparmor——Linux内核中的强制访问控制系统

      AppArmor 因为最近在研究OJ(oline judge)后台的安全模块的实现,所以一直在研究Linux下沙箱的东西,同时发现了Apparmor可以提供访问控制. AppArmor(Appli ...

  8. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK fla ...

  9. AFNetworking vs ASIHTTPRequest vs MKNetworkKit

    AFNetworking vs ASIHTTPRequest vs MKNetworkKit

  10. android手机连接PC无法正常安装驱动

    工作当中我们经常会遇到Android手机连接PC的时候无法正确安装驱动,或者安装失败.当然找到正确的驱动文件时首选的解决方案,如果正确的驱动文件依旧无法安装成功我们可以打开我的电脑-->属性-- ...