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

【题意】

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

【题解】

用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. cmd 命令操纵文件管理器、创建(删除)多级文件夹

    命令行打开文件夹窗口的六种方法 1. 使用 start 命令 # 打开指定文件夹 > start 路径 # 打开当前文件夹 > start . # 打开含空格文件夹 > start ...

  2. Django-CKeditor使用笔记

    1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...

  3. 湖南集训day3

    难度:☆☆☆☆☆☆☆ 此时相望不相闻,愿逐月华流照君 /* 23 233 223 啦啦啦德玛西亚 */ #include<iostream> #include<cstdio> ...

  4. codevs1225八数码难题(搜索·)

    1225 八数码难题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description Yours和zero在研究A*启 ...

  5. mybatis传参问题总结

    一. 传入单个参数 当传入的是单个参数时,方法中的参数名和sql语句中参数名一致即可 List<User> getUser(int id); <select id="get ...

  6. Centos7基本命令

    shell基本命令 linux命令行的组成结构 linux系统命令操作语法格式 命令 空格 参数 空格 文件路径或者需要处理的内容 rm   -rf   /tmp/* ls   -la   /home ...

  7. ACM_“IP地址”普及(进制转换)

    “IP地址”普及 Time Limit: 2000/1000ms (Java/Others) Problem Description: 大家都知道最近广财大校园网提速,现在就跟大家普及一下简单的互联网 ...

  8. springMVC是什么等七个问题

  9. 1CSS简介

    -------------------------------------------------------------------------------------------------- - ...

  10. Zabbix Server参数文件详解

    Zabbix的配置文件一般有三种: zabbix_server.conf:zabbix server的配置文件 zabbix_proxy.conf:zabbix proxy的配置文件 zabbix_a ...