【链接】 我是链接,点我呀:)

【题意】

有人转载官方号的动态。
又有其他人转载其他人转载的动态.
问你最长的一条转载动态的链有多长.

【题解】

用map把每个人的英文都转成小写的
然后从map中获取单词的标号
转换成图。
然后从根节点开始dfs即可

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)400;
static class Task{
int n,cnt,ans = 0;
ArrayList []g; void dfs(int x,int dep) {
ans = Math.max(ans,dep);
for (int i = 0;i < (int)g[x].size();i++) {
int y = (int)g[x].get(i);
dfs(y,dep+1);
}
} public void solve(InputReader in,PrintWriter out) {
g = new ArrayList[N+10];
HashMap<String,Integer> dic = new HashMap<String,Integer>();
for(int i = 1;i <= N;i++)g[i] = new ArrayList();
n = in.nextInt();
for (int i = 0;i < n;i++) {
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
String s1,s2; s1 = in.next();s2 = in.next();s2 = in.next(); char key;
for (int j = 0;j < (int)s1.length();j++) {
if (s1.charAt(j)>='A' && s1.charAt(j)<='Z') {
key = (char)(s1.charAt(j)-'A'+'a');
sb1.append(key);
}else {
key =(char)s1.charAt(j);
sb1.append(s1.charAt(j));
}
}
s1 = sb1.toString(); for (int j = 0;j < (int)s2.length();j++) {
if (s2.charAt(j)>='A' && s2.charAt(j)<='Z') {
key = (char)(s2.charAt(j)-'A'+'a');
sb2.append(key);
}else {
key =(char)s2.charAt(j);
sb2.append(key);
}
}
s2 = sb2.toString(); if (!dic.containsKey(s1)) {
dic.put(s1, ++cnt);
} if (!dic.containsKey(s2)) {
dic.put(s2, ++cnt);
} int x = dic.get(s1),y = dic.get(s2);
g[y].add(x);
}
dfs(dic.get("polycarp"),1);
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 522A】Reposts的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. 【POJ 1723】 SOLDIERS

    [题目链接] http://poj.org/problem?id=1723 [算法] 中位数 [代码] #include <algorithm> #include <bitset&g ...

  2. [模板]平衡树splay

    气死我了,调了一个下午+两节课,各种大大小小的错误,各种调QAQ,最后总之是调出来了. 其实就是一个双旋操作,然后其他就是左儿子<当前节点<右儿子,剩下就是细节了. 题干: 题目描述 您需 ...

  3. 父页面调用子页面js的方法

    iframe子页面调用父页面javascript函数的方法今天遇到一个iframe子页面调用父页面js函数的需求,解决起来很简单,但是在chrome浏览器遇到一点小问题.顺便写一下iframe的父页面 ...

  4. codeforces——贪心

    codeforces 804A Find Amir   http://codeforces.com/problemset/problem/804/A /* 题意:给定n个学校,需要遍历所有学校,可从任 ...

  5. Django day27 认证组件,权限组件()

    一:认证组件 1.写一个类 class LoginAuth(): # 函数名一定要叫authenticate,接收必须两个参数,第二个参数是request对象 def authenticate(sel ...

  6. SpringBoot入门之HelloWorld

    1.SpringBoot简介 百度百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...

  7. Spring Web MVC核心架构

    可以查看DispatherServlet中的源代码,就是doDispatch()方法!

  8. SQL SERVER中存储过程IN 参数条件的使用!!!

    正常的传递  @SendStationID='''1'',''2''' 是无效,改用 @SendStationID='1,2,3,003,002' 调用以下的存储过程可以实现in 查询效果 USE [ ...

  9. Sublime Text2安装emmet

    一.安装Package Control 如果Preferences中没有Package Control,需要手动安装.安装方法如下: 访问Package Controls站点复制一段python命令安 ...

  10. HashMap的尾部遍历问题--Tail Traversing

    在看网上HashMap的resize()设计时,提到尾部遍历.   JDK1.7的HashMap在实现resize()时,新table[]的列表采用LIFO方式,即队头插入.这样做的目的是:避免尾部遍 ...