codeforces 522 A. Reposts
http://codeforces.com/problemset/problem/522/A 题意:给定某条消息的传播路径。问最远传播的距离。。 思路:其实就是问树的深度。。直接dfs就行了。。
存的时候用map<string,vector
1/* ***********************************************
2Author :111qqz
3Created Time :2015年12月05日 星期六 16时41分41秒
4File Name :code/cf/problem/522A.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25
26
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=2E2+7;
34map<string,vector<string> > mp;
35map<string,bool>vis;
36string from,to,nouse;
37int ans;
38int n;
39
40void dfs(string cur,int depth)
41{
42// cout<<"cur:"<<cur<<" depth:"<<depth<<endl;
43 vis[cur] = true;
44 ans = max(ans,depth);
45 for ( int i = 0 ; i < mp[cur].size() ; i++)
46 {
47 string v = mp[cur][i];
48 if (!vis[v])
49 dfs(v,depth+1);
50 }
51}
52
53string tran(string x)
54{
55 int len = x.length();
56 for ( int i = 0 ; i < len ; i++)
57 {
58 if (x[i]>='A'&&x[i]<='Z')
59 {
60 x[i] = char(x[i]+32);
61 }
62 }
63 return x;
64}
65int main()
66{
67 #ifndef ONLINE_JUDGE
68 freopen("code/in.txt","r",stdin);
69 #endif
70 mp.clear();
71 scanf("%d",&n);
72// getchar();
73 for ( int i = 0 ; i < n ; i++)
74 {
75 cin>>to>>nouse>>from;
76 to = tran(to);
77 from = tran(from);
78// getchar();
79 // cout<<"to:"<<to<<endl<<" nouse:"<<nouse<<endl<<" from:"<<from<<endl;
80 mp[from].push_back(to);
81 }
82 ans = 1;
83 dfs("polycarp",1);
84 printf("%d\n",ans);
85
86 #ifndef ONLINE_JUDGE
87 fclose(stdin);
88 #endif
89 return 0;
90}