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

【题意】

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

【题解】

用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. bzoj 2333 [SCOI2011]棘手的操作 —— 可并堆

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2333 稍微复杂,参考了博客:http://hzwer.com/5780.html 用 set ...

  2. bzoj1477 && exgcd学习笔记

    exgcd 由于忘记了exgcd,这道题就没做出来... exgcd的用处是求ax+by=gcd(a,b)这样方程的解 大概是这个样子的 void ext_gcd(long long a, long ...

  3. shell脚本-基础

    shell脚本-基础 编程基础 程序是指令+ 数据 程序编程风格: 过程式:以指令为中心,数据服务于指令 对象式:以数据为中心,指令服务于数据 shell 程序提供了编程能力,解释执行. 计算运行二进 ...

  4. ie8 js编译器对象为空或不是对象的一个小问题

    昨天在遍历json串的时候碰到了如下图所示的问题,除ie8以下版本的浏览器运行都是正常的, 部分代码如下: 1 var Workmodel=function(){ 2 model_json=[ 3 { ...

  5. [Swift通天遁地]四、网络和线程-(10)处理图片:压缩、缩放、圆角、CoreImage滤镜、缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. 【BZOJ2762】[JLOI2011]不等式组(树状数组)

    题目: BZOJ2762 分析: 加入的不等式分三种情况 当\(a>0\),可以变成\(x>\lfloor \frac{c-b}{a}\rfloor\) 当\(a=0\),若\(b> ...

  7. mysql数据库存储的引擎和数据类型

    一.查看支持的存储引擎 SHOW ENGINES \G; 或者 SHOW VARIABLES LIKE 'have%'; 二.安装版mysql的默认引擎是InnoDB,免安装版默认引擎是MyISAM ...

  8. 2018.10.9 logstash启动慢的问题解决

    问题描述: 线上部署logstash 启动非常缓慢,达到了10分钟 问题解决 忍无可忍 网上资料基本都是熵过低导致jruby启动缓慢的问题,需要安装haveged 参考https://www.jian ...

  9. Unity学习-摄像机的使用(六)

    快速对齐摄像机 [选择摄像机-GameObject-Align With View] Game模板中显示的界面,就是摄像机拍摄后的画面 本次学习案例 添加一个地形,一个点光源,三个Cube   了解摄 ...

  10. UVM基础之----uvm_object

    uvm_void The uvm_void class is the base class for all UVM classes. uvm_object: The uvm_object class ...