1176. Hyperchannels

博客介绍了1176. Hyperchannels,包含输入、输出及示例内容,文章转载自https://www.cnblogs.com/sdau--codeants/p/3260094.html 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

inputoutput
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 Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
***************************************************************************************
深搜求欧拉回路并记录路径(注:vector   void   reverse(),根据实际重新计算vector容量,好用得加<algorithm>预处理!!!!!!!!!!!!!!!!!!!!)
***************************************************************************************
 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<queue>
 8 #include<algorithm>
 9 using namespace std;
10 vector<int>adj[10001];
11 vector<int>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<path.size()-1;i++)
37         cout<<path[i]<<' '<<path[i+1]<<endl;
38        cout<<endl;
39        return 0;
40   }
View Code

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值