博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1176. Hyperchannels
阅读量:6333 次
发布时间:2019-06-22

本文共 2612 字,大约阅读时间需要 8 分钟。

1176. 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
 (
A
 
 
N) 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 20 0 1 00 0 1 01 1 0 10 0 1 0
2 44 11 22 11 44 2
Problem Author: Pavel Atnashev
Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
***************************************************************************************
深搜求欧拉回路并记录路径(注:vector   void   reverse(),根据实际重新计算vector容量,好用得加<algorithm>预处理!!!!!!!!!!!!!!!!!!!!)
***************************************************************************************
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std;10 vector
adj[10001];11 vector
path;12 int n,m,i,j,k;13 void dfs(int s)//深搜求欧拉回路14 {15 while(adj[s].size())16 {17 int p=adj[s].back();18 adj[s].pop_back();19 dfs(p);20 21 }22 path.push_back(s);//压入路径23 }24 int main()25 {26 cin>>n>>m;27 for(i=1;i<=n;i++)28 for(j=1;j<=n;j++)29 {30 cin>>k;31 if(i!=j&&k==0)32 adj[i].push_back(j);33 }34 dfs(m);35 reverse(path.begin(),path.end());36 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3260094.html

你可能感兴趣的文章
修改Eclipse中项目在Apache Tomcat中的部署路径
查看>>
单例模式完全剖析
查看>>
【转】75种常用的jquery网页特效
查看>>
分析:Android系统刷机后,第一次开机启动很慢的原因
查看>>
Vue2入门
查看>>
派生自QWidget的控件使用stylesheet
查看>>
关键字extern和static
查看>>
北广传媒RTMP流媒体服务器漏洞
查看>>
shell学习
查看>>
citrix xenserver 相关问题合集 (一) xenserver 6.2网卡丢失无法启动
查看>>
MySQL笔记
查看>>
vmware克隆Centos6.8虚拟机网卡无法启动问题
查看>>
人形机器人管家
查看>>
字符串转数字
查看>>
公共消息提示框的使用
查看>>
设置开机自启的脚本,用户管理
查看>>
决心书
查看>>
你真的懂JAVA吗
查看>>
课程第九天内容《基础交换九》 补充内容 操作
查看>>
怎样使用U盘安装Windows系统
查看>>