2015年3月14日 星期六

2015/03/14 Codeforces 522A. Reposts

// http://codeforces.com/problemset/problem/522/A
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

map<string, int> m;
char c1[50], c2[50];

vector<int> v[300];

int N;

int mx = 0;

void DFS(int O, int d)
{
    mx = max(mx, d);

    for(auto t:v[O])
        DFS(t, d+1);
}

void change()
{
    int n1 = strlen(c1);

    for(int ci = 0; ci < n1; ci++)
        if( 'A' <= c1[ci] && c1[ci] <= 'Z'  )
            c1[ci] += 'a'-'A';

    int n2 = strlen(c2);

    for(int ci = 0; ci < n2; ci++)
        if( 'A' <= c2[ci] && c2[ci] <= 'Z'  )
            c2[ci] += 'a'-'A';
}

int main()
{
    scanf("%d", &N);

    for(int Ni = 1; Ni <= N; Ni++)
    {
        scanf("%s %*s %s", c1, c2);
        change();

        m[c1] = Ni;
        v[m[c2] ].push_back(Ni);
    }

    DFS(0, 1);

    printf("%d\n", mx);
}

沒有留言:

張貼留言