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

【题意】

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

【题解】

用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. openStack aio nova service-list neutron ext-list

  2. spark 操作Hive时遇到的问题

    To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).17/10/14 ...

  3. B. Mashmokh and ACM(dp)

    http://codeforces.com/problemset/problem/414/B B. Mashmokh and ACM time limit per test 1 second memo ...

  4. codevs1026商务旅行

    1036 商务旅行  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 某首都城市的商人要经常到各城镇去做 ...

  5. 乐字节-Java8核心特性实战之函数式接口

    什么时候可以使用Lambda?通常Lambda表达式是用在函数式接口上使用的.从Java8开始引入了函数式接口,其说明比较简单:函数式接口(Functional Interface)就是一个有且仅有一 ...

  6. Akka源码分析-Remote-收消息

    上一遍博客中,我们分析了网络链接建立的过程,一旦建立就可以正常的收发消息了.发送消息的细节不再分析,因为对于本地的actor来说这个过程相对简单,它只是创立链接然后给指定的netty网路服务发送消息就 ...

  7. JavaScript Date 日期操作

    在前端工程师的道路上,可能有时候需要与时间来打交道,下面我们来看一下日常对日期的操作,今天我们介绍的是Day.js插件 Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Mom ...

  8. 阿里邮箱绑定Foxmail失败的解决办法

    收件服务器地址: POP 服务器地址:pop3.mxhichina.com 端口110,SSL 加密端口995 或 IMAP 服务器地址:imap.mxhichina.com 端口143,SSL 加密 ...

  9. Linux命令(003) -- crontab

    一.准备知识 Linux下的任务调度分为两类:系统任务调度和用户任务调度. (1).系统任务调度 系统任务调度是系统周期性所要执行的工作,比如写缓存数据到硬盘.日志清理等.在/etc目录下有一个cro ...

  10. Linux命令(002) -- free

    一.准备知识 Linux和Windows系统在内存管理机制方面有很大的不同.在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然.这是Linux内存管理的 ...