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 ...
随机推荐
- HDU 1513 Palindrome(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 解题报告:给定一个长度为n的字符串,在这个字符串中插入最少的字符使得这个字符串成为回文串,求这个 ...
- phpcms某处储存型XSS(demo+本地演示)
文章转载:http://www.myhack58.com/Article/html/3/7/2016/71726.htm 详细说明: demo+本地演示存在xss漏洞的地方在商务中心的商家资料的我的资 ...
- java获得当前文件路径
第一种: File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); ...
- 《转》VS2012发布网站详细步骤
本文转载自MannyGuo 如果给您带来不便请联系博主 1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击& ...
- 《ASP.NET1200例》统计网站访问量源代码
void Application_Start(object sender, EventArgs e) { //在应用程序启动时运行的代码 int count=0; ...
- recv和send函数
转自 http://www.cnblogs.com/blankqdb/archive/2012/08/30/2663859.html 1. send解析 sockfd:指定发送端套接字描述符. bu ...
- iOS中的NSTimer 和 Android 中的Timer
首先看iOS的, Scheduling Timers in Run Loops A timer object can be registered in only one run loop at a t ...
- MySQL入门书籍和方法分享
本文罗列了一些适用于MySQL及运维入门和进阶使用的书籍. 背景:各大论坛上总是有很多同学咨询想学习数据库,或者是为入行DBA做些准备.几年来作为一个MySQL DBA的成长过程有一些积累和感悟,特此 ...
- codeforces B. Petya and Staircases 解题报告
题目链接:http://codeforces.com/problemset/problem/362/B 题目意思:给出整数n和m,表示有n级楼梯和m级dirty的楼梯,接下来m个数表示对应是哪一个数字 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...