ural 1434. Buses in Vasyuki
1434. Buses in Vasyuki
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
3 10 |
3 |
Problem Source: The 7th USU Open Personal Contest - February 25, 2006
/**
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 For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#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 = , M = ;
int n, m, St, Ed;
vector<int> Bus[M];
vector<int> Index[N];
int Dp[N], From[N], Que[N], Head, Tail; inline void Input()
{
scanf("%d%d", &m, &n);
For(i, , m)
{
int s, x;
scanf("%d", &s);
while(s--)
{
scanf("%d", &x);
Bus[i].pub(x);
Index[x].pub(i);
}
}
scanf("%d%d", &St, &Ed);
} inline void Solve()
{
For(i, , n) Dp[i] = INF;
Dp[St] = , From[St] = ;
Que[Head = Tail = ] = St;
while(Head <= Tail)
{
int u = Que[Head++];
//printf("%d\n", u);
int p = sz(Index[u]);
Rep(i, p)
{
int S = sz(Bus[Index[u][i]]);
Rep(j, S)
{
int v = Bus[Index[u][i]][j];
if(Dp[v] > Dp[u] + )
{
Dp[v] = Dp[u] + , From[v] = u;
Que[++Tail] = v;
}
}
}
} if(Dp[Ed] >= INF) puts("-1");
else
{
printf("%d\n", Dp[Ed]);
vector<int> Ans;
for(int x = Ed; x; x = From[x])
Ans.pub(x);
Ford(i, Dp[Ed], ) printf("%d ", Ans[i]);
printf("%d\n", Ed);
}
} int main()
{
Input();
Solve();
return ;
}
ural 1434. Buses in Vasyuki的更多相关文章
- URAL 1137Bus Routes (dfs)
Z - Bus Routes Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- 51nod 1434 理解lcm
1434 区间LCM 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 一个整数序列S的LCM(最小公倍数)是指最小的正 ...
- CF459C Pashmak and Buses (构造d位k进制数
C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- Eighth scrum meeting - 2015/11/2
由于之前的在线视频播放控件功能过于简单,我们今天从网上找了一个效果还不错的视频播放开源项目,在添加了复杂的依赖后终于能够正常使用了,效果比起之前来也好了很多,而且后续的视频下载功能也可以基于这个来开发 ...
- js实现把网页table导成Excel
//导出excel function exportExcel(DivID,strTitle){ if(DivID==null) { return false; } var jXls, myWorkbo ...
- 2014-08-07 SSDB 使用 rocksdb 引擎
http://www.ideawu.net/blog/archives/824.html 为了满足各位对 Facebook 出品的 rocksdb 的爱好, SSDB 数据库也可以使用 rocksdb ...
- 使用Discuz关键词服务器实现PHP中文分词
不同于使用自己的服务器进行分词,Discuz!在线中文分词服务是基于API返回分词结果的.在项目中,我们只需要一个函数即可方便地进行分词.关键词提取.以下是根据Discuz!在线分词服务API写的函数 ...
- 【云计算】docker daemon如何提供Restful的API
Docker Remote API 如何使用? docker 的 Remote API 定义如下: 这个API看着是http协议的但是我用 curl http://127.0.0.1:4243/con ...
- 【SpringMVC】SpringMVC系列1之HelloWorld
SpringMVC之HelloWorld 概述 SpringMVC 是基于 MVC 设计理念的优秀Web 框架,是目前最主流的 MVC 框架之一.Spring3.0 后全面超越 Struts2,成为最 ...
- SQL表值函数和标量值函数的区别
SQL表值函数和标量值函数的区别 写sql存储过程经常需要调用一些函数来使处理过程更加合理,也可以使函数复用性更强,不过在写sql函数的时候可能会发现,有些函数是在表值函数下写的有些是在标量值下写的, ...
- 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- DP:Corn Fields(POJ 3254)
北大教你如何高效养牛(误)(点我查看) 2015-08-21: 问题的大意就是有一片稻田,里面有很多坑,你要在上面种稻谷,然后呢田里面还会养牛,牛不喜欢扎堆吃饭,所以呢你种的稻谷要间隔种在坑里面,所 ...
- project.json
概述 项目相关配置,由原来的cocos2d.js中转移到project.json中,该文件需要与index.html同级,一般建议放在根目录下. 字段说明 debugMode 相当于原来的COCOS2 ...