http://acm.timus.ru/problem.aspx?space=1&num=1837

 #include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
vector<int>q[]; struct node
{
string s;
int num;
bool operator <(const node &a)const
{
return s<a.s;
}
} p1[*];
int t1; int getnum(string c)
{
for(int i=; i<t1; i++)
{
if(c==p1[i].s) return i;
}
p1[t1++].s=c;
return t1-;
} void bfs(int str)
{
queue<int>qq;
bool vis[];
memset(vis,false,sizeof(vis));
qq.push(str);
p1[str].num=;
vis[str]=true;
while(!qq.empty())
{
int m=qq.front();
qq.pop();
for(int j=; j<q[m].size(); j++)
{
int x=q[m][j];
vis[x]=true;
if(p1[x].num==-){
p1[x].num=p1[m].num+;
qq.push(x);
}
}
}
} int main()
{
int t;
scanf("%d",&t);
string s1,s2,s3;
t1=;
int k1,k2,k3;
for(int i=; i<=t; i++)
{
cin>>s1>>s2>>s3;
k1=getnum(s1);
k2=getnum(s2);
k3=getnum(s3);
q[k1].push_back(k2);
q[k1].push_back(k3);
q[k2].push_back(k1);
q[k2].push_back(k3);
q[k3].push_back(k1);
q[k3].push_back(k2);
}
for(int j=; j<t1; j++)
{
p1[j].num=-;
}
string s4="Isenbaev";
int num1;
bool flag=false;
for(int j=; j<t1; j++)
{
if(p1[j].s==s4)
{
flag=true;
num1=j;
break;
}
}
if(flag)
bfs(num1);
sort(p1,p1+t1);
for(int i=; i<t1; i++)
{
if(p1[i].num==-)
{
cout<<p1[i].s<<" "<<"undefined"<<endl;
}
else
cout<<p1[i].s<<" "<<p1[i].num<<endl;
}
return ;
}

ural 1837 Isenbaev's Number的更多相关文章

  1. ural 1837. Isenbaev's Number bfs

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1837 描述: Isenbaev是国外的一个大牛. 现在有许多人要参加ACM ICPC. ...

  2. URAL 1837. Isenbaev&#39;s Number (map + Dijkstra || BFS)

    1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...

  3. 1837. Isenbaev's Number(floyd)

    1837 被数据结构部分打击的不行了 换地 刷点简单的 图论第一题 floyd水过 #include <iostream> #include<cstdio> #include& ...

  4. ural 1748 The Most Complex Number 和 丑数

    题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...

  5. URAL 1748. The Most Complex Number(反素数)

    题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. ( ...

  6. URAL 1748 The Most Complex Number

    题目链接:https://vjudge.net/problem/11177 题目大意: 求小于等于 n 的最大反素数. 分析: n <= 10^18,而前20个素数的乘积早超过10^18,因此可 ...

  7. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  8. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  9. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

随机推荐

  1. 尚学堂 JAVA DAY11 概念总结

    1.冒泡排序算法 <升序排列> 思路1: 数组长度为n,那么要对数组进行n-1次遍历; step 1---从数组的第一个数开始,两两比较,如果第一个数 > 第二个数,将二者进行交换: ...

  2. 解决NoSuchMethodError with Spring MutableValues异常问题

    今天下午项目启动时,遇到一个异常,导致无法启动: [ 221] ERROR - work.web.context.ContextLoader - Context initialization fail ...

  3. 计算两点距离 ios

    //计算两点距离 -(float)distanceBetweenTwoPoint:(CGPoint)point1 point2:(CGPoint)point2 { ) + powf(point1.y ...

  4. hdu 3631 Shortest Path(Floyd)

    题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...

  5. [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State

    ngrx/store is a library that simplifies common RxJS patterns for managing state and gives you an eas ...

  6. ASSERT_VALID和ASSERT宏分析

    这个宏都是MFC的调试宏. ASSERT_VALID宏用来在运行时检查一个对象的内部合法性,比如说现在有一个学生对象,我们知道每个学生的年龄一定大于零,若年龄小于零,则该学生对象肯定有问题. 事实上, ...

  7. SQLServer 工具技巧

    SQLServerProfiler 的使用 http://www.jikexueyuan.com/course/1712.html

  8. C#Linq的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. webform 简单的服务器控件。

    服务器基本控件: 1    textbox text:获取或设置文本        textmode:单行/多行/密码...        wrap:是否换行        rows:行数      ...

  10. python单元测试之unittest

    unittest是python标准库,从2.1开始就有. 标准的使用流程: 1:实现一个unittest.TestCase的子类 2:在其中定义以_test开头的实例函数 3:用unittest.ma ...