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. timestamp 类型的索引

    由这条语句datetime.strftime('2014/12/05','%Y/%m/%d')转换出来的索引 是pandas内置类型相同,如果使用datetime.strftime('2014/12/ ...

  2. grep -i 不区分大小写

    # rpm -qa|grep -i "mysql" MySQL-server--.rhel5.x86_64 MySQL-test--.rhel5.x86_64 MySQL-embe ...

  3. map find 是线程安全的吗

    测试环境gcc4.8.2     iterator find ( const key_type& k ); const_iterator find ( const key_type& ...

  4. 算法系列:HMM

    隐马尔可夫(HMM)好讲,简单易懂不好讲. 用最经典的例子,掷骰子.假设我手里有三个不同的骰子.第一个骰子是我们平常见的骰子(称这个骰子为D6),6个面,每个面(1,2,3,4,5,6)出现的概率是1 ...

  5. Solr入门之(8)中文分词器配置

    Solr中虽然提供了一个中文分词器,但是效果很差,可以使用IKAnalyzer或Mmseg4j 或其他中文分词器. 一.IKAnalyzer分词器配置: 1.下载IKAnalyzer(IKAnalyz ...

  6. 搜索引擎爬虫技术研究(爬虫框架)-WebCollector

    一.简介: https://github.com/CrawlScript/WebCollector/blob/master/README.zh-cn.md 二.使用: <dependency&g ...

  7. C语言字符串长度(转)

    C语言字符串长度的计算是编程时常用到的,也是求职时必考的一项. C语言本身不限制字符串的长度,因而程序必须扫描完整个字符串后才能确定字符串的长度. 在程序里,一般会用strlen()函数或sizeof ...

  8. PHP模拟POST请求,获取response内容

    /* * 模拟POST请求,获取response内容 */ protected function curl($url, $type, $header, $data) { $CURL_OPTS = ar ...

  9. 让sql语句不排序,按照in语句的顺序返回结果

    SELECT * FROM EVENT WHERE eventId IN(443,419,431,440,420,414,509)  ORDER BY INSTR(',443,419,431,440, ...

  10. 原生JavaScript 全特效微博发布面板效果实现

    javaScript实现微博发布面板效果.---转载白超华 采用的js知识有: 正则表达式区分中英文字节.随机数生成等函数 淡入淡出.缓冲运动.闪动等动画函数 onfocus.onblur.oninp ...