1072. Routing

Time limit: 1.0 second
Memory limit: 64 MB
There is a TCP/IP net of several computers. It means that:
  1. Each computer has one or more net interfaces.
  2. Each interface is identified by its IP-address and a subnet mask — these are two four-byte numbers with a point after each byte. A subnet mask has a binary representation as follows: there are k 1-bits, then — m 0-bits, k+m=8*4=32 (e.g., 212.220.35.77 — is an IP-address and 255.255.255.128 — is a subnet mask).
  3. Two computers belong to the same subnet, if and only if (IP1 AND NetMask1) = (IP2 AND NetMask2), where IPi and NetMaski — are an IP-address and subnet mask of i-th computer, AND — is bitwise.
  4. A packet is transmitted between two computers of one subnet directly.
  5. If two computers belong to different subnets, a packet is to be transmitted via some other computers. The packet can pass from one subnet to another only on computer that has both subnets interfaces.
Your task is to find the shortest way of a packet between two given computers.

Input

The first line contains a number N — an amount of computers in the net, then go N sections, describing interfaces of each computer. There is a number K in the first line of a section — that is an amount of interfaces of the computer, then go K lines — descriptions of the interfaces, i.e. its IP-address and a subnet mask. The last line of an input contains two integers — the numbers of the computers that you are to find a way between them.
You may assume that 2 ≤ N ≤ 90 and K ≤ 5.

Output

The word “Yes” if the route exists, then in the next line the computer numbers passed by the packet, separated with a space. The word “No” otherwise.

Sample

input output
6
2
10.0.0.1 255.0.0.0
192.168.0.1 255.255.255.0
1
10.0.0.2 255.0.0.0
3
192.168.0.2 255.255.255.0
212.220.31.1 255.255.255.0
212.220.35.1 255.255.255.0
1
212.220.31.2 255.255.255.0
2
212.220.35.2 255.255.255.0
195.38.54.65 255.255.255.224
1
195.38.54.94 255.255.255.224
1 6
Yes
1 3 5 6
Problem Author: Evgeny Kobzev
Problem Source: Ural State Univerisity Personal Contest Online February'2001 Students Session
Difficulty: 464 
 
题意:给出n台计算机,每台计算机有若干对IP地址以及子网掩码,当且仅当存在(IP地址i AND 子网掩码i) = (IP地址j AND 子网掩码j)时,两台计算机才可以联系。
问从一台计算机到另一台计算机最短要经过多少计算机。
输出方案。
分析:实际上就是最短路。
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n;
int length[N];
vector<unsigned int> feature[N];
bool graph[N][N];
queue<int> que;
int dp[N], from[N], st, ed; inline unsigned int Get()
{
const static unsigned int fact[] = {, , , };
unsigned int ret = ;
for(int i = ; i < ; i++)
{
int x = (unsigned int) Getint();
ret += x * fact[i];
}
return ret;
} inline void Input()
{
scanf("%d", &n);
for(int i = ; i <= n; i++)
{
scanf("%d", &length[i]);
//cout << i << ": ";
for(int j = ; j <= length[i]; j++)
{
unsigned int x, y;
x = Get();
y = Get();
feature[i].pub(x & y);
//cout << (x & y) << ' ';
}
//cout << endl;
}
scanf("%d%d", &st, &ed);
} inline bool find(int x, int y)
{
int len1 = sz(feature[x]), len2 = sz(feature[y]);
for(int i = ; i < len1; i++)
for(int j = ; j < len2; j++)
if(feature[x][i] == feature[y][j])
return ;
return ;
} inline void Solve()
{
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
if(i != j && find(i, j))
graph[i][j] = ; for(int i = ; i <= n; i++)
from[i] = , dp[i] = INF;
dp[st] = ;
que.push(st);
while(sz(que))
{
int u = que.front();
que.pop();
for(int i = ; i <= n; i++)
if(graph[u][i] && dp[i] > dp[u] + )
{
dp[i] = dp[u] + ;
from[i] = u;
que.push(i);
}
} if(dp[ed] == INF) printf("No\n");
else
{
printf("Yes\n");
vector<int> ans;
for(int x = ed; x; x = from[x]) ans.pub(x);
int length = sz(ans);
for(int i = length - ; i >= ; i--)
printf("%d ", ans[i]);
printf("%d\n", ans[]);
}
} int main()
{
freopen("d.in", "r", stdin);
Input();
Solve();
return ;
}

ural 1072. Routing的更多相关文章

  1. URAL 1072 Routing(最短路)

    Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. It mea ...

  2. ASP.NET路由[ASP.NET Routing]

    ASP.NET路由[ASP.NET Routing] ASP.NET路由允许你在使用URL时不必匹配到网站中具体的文件,因为这个URL不必匹配到一个文件,你使用了描述用户行为且更容易被用户理解的URL ...

  3. 解读ASP.NET 5 & MVC6系列(12):基于Lamda表达式的强类型Routing实现

    前面的深入理解Routing章节,我们讲到了在MVC中,除了使用默认的ASP.NET 5的路由注册方式,还可以使用基于Attribute的特性(Route和HttpXXX系列方法)来定义.本章,我们将 ...

  4. 解读ASP.NET 5 & MVC6系列(11):Routing路由

    新版Routing功能介绍 在ASP.NET 5和MVC6中,Routing功能被全部重写了,虽然用法有些类似,但和之前的Routing原理完全不太一样了,该Routing框架不仅可以支持MVC和We ...

  5. [ASP.NET MVC 小牛之路]07 - URL Routing

    我们知道在ASP.NET Web Forms中,一个URL请求往往对应一个aspx页面,一个aspx页面就是一个物理文件,它包含对请求的处理. 而在ASP.NET MVC中,一个URL请求是由对应的一 ...

  6. ASP.NET MVC Routing学习笔记(一)

    Routing在ASP.NET MVC中是非常核心的技术,属于ASP.NET MVC几大核心技术之一,在使用Routing之前,得先引入System.Web.Routing,但其实不用这么麻烦,因为在 ...

  7. Routing 功能概述 - 每天5分钟玩转 OpenStack(98)

    路由服务(Routing)提供跨 subnet 互联互通功能. 例如前面我们搭建了实验环境: cirros-vm1      172.16.100.3        vlan100 cirros-vm ...

  8. .NET/ASP.NET Routing路由(深入解析路由系统架构原理)

    阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...

  9. 理解 OpenStack 高可用(HA)(3):Neutron 分布式虚拟路由(Neutron Distributed Virtual Routing)

    本系列会分析OpenStack 的高可用性(HA)概念和解决方案: (1)OpenStack 高可用方案概述 (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)N ...

随机推荐

  1. SQL Server多表多列更新

    student表: lag表: 要求将student表stu_id列为1的stu_nick列和stu_phont列的数据更新为lag表的lag_nick列和lag_phone列. SQL语句: upd ...

  2. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  3. IE6中使用通用选择器模拟子选择器效果

    IE6及更低版本不支持高级选择器:IE7有个bug,对于子选择器和相邻同胞选择器,如果父元素和子元素有HTML注释,会出问题. 下面我们使用通用选择器来模拟子选择器的效果. 原理:首先在所有后代上应用 ...

  4. Jquery.Datatables 导出excel

    按钮(Buttons) BUttons v1.1.2 下载地址:http://pan.baidu.com/s/1c0Jhckg JSZip v2.5.0-21-g4fd4fc1 下载地址:http:/ ...

  5. Sphinx的介绍和原理探索

    What/Sphinx是什么 定义 Sphinx是一个全文检索引擎. 特性 索引和性能优异 易于集成SQL和XML数据源,并可使用SphinxAPI.SphinxQL或者SphinxSE搜索接口 易于 ...

  6. 设计模式学习之命令模式(Command,行为型模式)(12)

    一.命令模式的定义 命令模式属于对象的行为型模式.命令模式是把一个操作或者行为抽象为一个对象中,通过对命令的抽象化来使得发出命令的责任和执行命令的责任分隔开.命令模式的实现可以提供命令的撤销和恢复功能 ...

  7. Pyqt phonon的使用

    本文是用Pyqt实现了下网上一个Qt版大牛关于phonon的介绍 Qt phonon地址:http://wenku.baidu.com/link?url=nH_dZ8lZbXHy8N5__8jAWLX ...

  8. 南阳理工 题目9:posters(离散化+线段树)

    posters 时间限制:1000 ms  |  内存限制:65535 KB 难度:6   描述 The citizens of Bytetown, AB, could not stand that ...

  9. WinDbg 命令三部曲:(一)WinDbg 命令手册

    本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 系列博文 <WinDbg 命令三部曲:(一)WinDbg 命令手册> <WinDb ...

  10. CentOS版本选择说明

    官方下载站http://www.centos.org/download/ 所有版本下载地址http://vault.centos.org/ 首先对一些镜像文件做个简单的介绍: LiveCD一般用来修复 ...