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. 快速求幂(Quick Exponentiation)

    接触ACM没几天,向各路大神求教,听说ACM主要是研究算法,所以便开始了苦逼的算法学习之路.话不多说,RT所示,学习快速求幂. 在头文件<math.h>或是<cmath>中,d ...

  2. linux之utime函数解析

    [lingyun@localhost utime]$ ls hello  utime.c  world [lingyun@localhost utime]$ cat utime.c  /******* ...

  3. 基于wax的lua IOS插件开发

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf Objective-C的运行时支持新增类型和方法,但是由于 ...

  4. 线段树---HDU1166敌兵布阵

    这个是线段树中最入门的题目,但是由于不了解线段树的概念,当然更不知道怎么样,所以觉得挺费劲,整了一会发现还是基本的思想,就是还是将一个线段继续分割,一直分割到不能分割,这道题目是知道多少个军营,也就是 ...

  5. 你以为你了解最常用的string.substring()的几个常见问题吗?

    ---恢复内容开始--- 前言: 1.项目中我们难免会用到各种对字符串的处理方法,可是你曾知道substring()这个用法别有洞天?你考虑过一下几个情况吗? 使用Substring()时的正确写法: ...

  6. h5 canvas

    概述 Canvas API(画布)用于在网页实时生成图像,并且可以操作图像内容,基本上它是一个可以用JavaScript操作的位图(bitmap). 使用前,首先需要新建一个canvas网页元素. & ...

  7. this computer does not support Intel Virtualization Technology (VT-x) .Haxm can'not be installed

    this computer does not support Intel Virtualization Technology (VT-x) .Haxm can'not be installed 本机不 ...

  8. ASP.NET获取根目录的方法集合

    编写程序的时候,经常需要用的项目根目录,自己总结如下: 1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法 ...

  9. HTML5 学习

    1.<header> 标签定义文档的页眉(介绍信息) 标签是 HTML 5 中的新标签 <header> <h1>Welcome to my homepage< ...

  10. jQuery mini ui 2

    1.<a class="mini-button" iconCls="icon-add" onclick="addRow()" plai ...