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 ...
随机推荐
- timestamp 类型的索引
由这条语句datetime.strftime('2014/12/05','%Y/%m/%d')转换出来的索引 是pandas内置类型相同,如果使用datetime.strftime('2014/12/ ...
- grep -i 不区分大小写
# rpm -qa|grep -i "mysql" MySQL-server--.rhel5.x86_64 MySQL-test--.rhel5.x86_64 MySQL-embe ...
- map find 是线程安全的吗
测试环境gcc4.8.2 iterator find ( const key_type& k ); const_iterator find ( const key_type& ...
- 算法系列:HMM
隐马尔可夫(HMM)好讲,简单易懂不好讲. 用最经典的例子,掷骰子.假设我手里有三个不同的骰子.第一个骰子是我们平常见的骰子(称这个骰子为D6),6个面,每个面(1,2,3,4,5,6)出现的概率是1 ...
- Solr入门之(8)中文分词器配置
Solr中虽然提供了一个中文分词器,但是效果很差,可以使用IKAnalyzer或Mmseg4j 或其他中文分词器. 一.IKAnalyzer分词器配置: 1.下载IKAnalyzer(IKAnalyz ...
- 搜索引擎爬虫技术研究(爬虫框架)-WebCollector
一.简介: https://github.com/CrawlScript/WebCollector/blob/master/README.zh-cn.md 二.使用: <dependency&g ...
- C语言字符串长度(转)
C语言字符串长度的计算是编程时常用到的,也是求职时必考的一项. C语言本身不限制字符串的长度,因而程序必须扫描完整个字符串后才能确定字符串的长度. 在程序里,一般会用strlen()函数或sizeof ...
- PHP模拟POST请求,获取response内容
/* * 模拟POST请求,获取response内容 */ protected function curl($url, $type, $header, $data) { $CURL_OPTS = ar ...
- 让sql语句不排序,按照in语句的顺序返回结果
SELECT * FROM EVENT WHERE eventId IN(443,419,431,440,420,414,509) ORDER BY INSTR(',443,419,431,440, ...
- 原生JavaScript 全特效微博发布面板效果实现
javaScript实现微博发布面板效果.---转载白超华 采用的js知识有: 正则表达式区分中英文字节.随机数生成等函数 淡入淡出.缓冲运动.闪动等动画函数 onfocus.onblur.oninp ...