ural 1072. Routing
1072. Routing
Memory limit: 64 MB
- Each computer has one or more net interfaces.
- 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).
- 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.
- A packet is transmitted between two computers of one subnet directly.
- 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.
Input
Output
Sample
input | output |
---|---|
6 |
Yes |
Problem Source: Ural State Univerisity Personal Contest Online February'2001 Students Session
/**
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的更多相关文章
- URAL 1072 Routing(最短路)
Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. It mea ...
- ASP.NET路由[ASP.NET Routing]
ASP.NET路由[ASP.NET Routing] ASP.NET路由允许你在使用URL时不必匹配到网站中具体的文件,因为这个URL不必匹配到一个文件,你使用了描述用户行为且更容易被用户理解的URL ...
- 解读ASP.NET 5 & MVC6系列(12):基于Lamda表达式的强类型Routing实现
前面的深入理解Routing章节,我们讲到了在MVC中,除了使用默认的ASP.NET 5的路由注册方式,还可以使用基于Attribute的特性(Route和HttpXXX系列方法)来定义.本章,我们将 ...
- 解读ASP.NET 5 & MVC6系列(11):Routing路由
新版Routing功能介绍 在ASP.NET 5和MVC6中,Routing功能被全部重写了,虽然用法有些类似,但和之前的Routing原理完全不太一样了,该Routing框架不仅可以支持MVC和We ...
- [ASP.NET MVC 小牛之路]07 - URL Routing
我们知道在ASP.NET Web Forms中,一个URL请求往往对应一个aspx页面,一个aspx页面就是一个物理文件,它包含对请求的处理. 而在ASP.NET MVC中,一个URL请求是由对应的一 ...
- ASP.NET MVC Routing学习笔记(一)
Routing在ASP.NET MVC中是非常核心的技术,属于ASP.NET MVC几大核心技术之一,在使用Routing之前,得先引入System.Web.Routing,但其实不用这么麻烦,因为在 ...
- Routing 功能概述 - 每天5分钟玩转 OpenStack(98)
路由服务(Routing)提供跨 subnet 互联互通功能. 例如前面我们搭建了实验环境: cirros-vm1 172.16.100.3 vlan100 cirros-vm ...
- .NET/ASP.NET Routing路由(深入解析路由系统架构原理)
阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...
- 理解 OpenStack 高可用(HA)(3):Neutron 分布式虚拟路由(Neutron Distributed Virtual Routing)
本系列会分析OpenStack 的高可用性(HA)概念和解决方案: (1)OpenStack 高可用方案概述 (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)N ...
随机推荐
- JavaScript数组排序
JavaScript的sort方法排序是有问题的,我们可以给sort方法传一个参数 function Compare(value1, value2) { //数字排序的函数参数 if (value1 ...
- python处理html的table标签
转载:http://www.xuebuyuan.com/583071.html python处理html的table标签 2012年01月06日 ⁄ 综合 ⁄ 共 5279字 ⁄ 字号 小 中 大 ⁄ ...
- Python中如何读取xml的数据
<?xml version="1.0" encoding="utf-8" ?> - <catalog> <maxid>4&l ...
- CocoaPods 安装
虽然网上关于CocoaPods安装教程多不胜数,但是我在安装的过程中还是出现了很多错误,所以大家可以照下来步骤装一下,我相信会很好用. 前言 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正 ...
- sql server 时间小汇
SQL server DATE函数 (1)getdate 返回当前系统的日期和时间,精确到3毫秒 要求:获得系统的当前时间 语句:SELECT getdate() 执行结果: 注:getutcda ...
- Tkprof工具详解一
注明:一些文章是从别人的博客中转载过来的,方便自己以后查阅:在数据库生成的oracle trace文件中,可读性是比较差的,此时可使用tkprof工具来格式化trace文件,tkprof是一个命令 ...
- AspectFill VS. AspectFit
从去年10月进入公司,到现在差不多忙碌了3个月,期间几乎所有精力和时间都花在了公司的项目上,有很多工作学习的心得一直没有总结,趁周末无事就来使这写一写. 除了刚进公司的那一个月是做一些修修补补的工作, ...
- css 妙味 总结
技巧一: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- centos6.4下安装php的imagick和imagemagick扩展教程
imagick在centos6.4的安装方法: .安装ImageMagick 代码如下: wget http://soft.vpser.net/web/imagemagick/ImageMagick- ...
- C# Settings使用小结
本篇博客将介绍C#中Settings的使用. 首先介绍一个桌面程序中的例子,当我们新安装一个软件,软件启动后会有例如新手指导等窗体弹出来,每次都需要自己去关闭它.当然这些软件都会提供例如不再显示等功能 ...