Example #1
0
            public void Solve()
            {
                int N = NextInt();
                var g = new CostGraph(N);

                (N - 1).REP(i =>
                {
                    int ai = NextInt() - 1, bi = NextInt() - 1;
                    g.Add(ai, bi, 1, false);
                });

                var dist = new int[2, N];

                2.REP(i => N.REP(j => dist[i, j] = int.MaxValue));

                Action <int, int, int> dfs = null;

                dfs = (crr, dis, fs) =>
                {
                    if (dist[fs, crr] != int.MaxValue)
                    {
                        return;
                    }
                    dist[fs, crr] = dis;
                    foreach (var edge in g.Adjacency[crr])
                    {
                        dfs(edge.To, dis + 1, fs);
                    }
                };

                dfs(0, 0, 0);
                dfs(N - 1, 0, 1);

                var fc = 0;
                var sc = 0;

                for (int i = 0; i < N; i++)
                {
                    if (dist[0, i] <= dist[1, i])
                    {
                        fc++;
                    }
                    else
                    {
                        sc++;
                    }
                }

                if (fc > sc)
                {
                    "Fennec".WL();
                }
                else
                {
                    "Snuke".WL();
                }

                return;
            }
Example #2
0
            public void Solve()
            {
                var N     = NextInt();
                var graph = new CostGraph(N);

                (N - 1).REP(i => {
                    int ai = NextInt(), bi = NextInt();
                    ai--;
                    bi--;
                    graph.Add(ai, bi, 1, false);
                });

                var distances = new int[2, N];

                2.REP(i => N.REP(j => distances[i, j] = int.MaxValue));

                Func <int, int, int, bool> dfs = null;

                dfs = (current, distance, phase) => {
                    if (distances[phase, current] != int.MaxValue)
                    {
                        return(true);
                    }
                    distances[phase, current] = distance;
                    foreach (var edge in graph.Adjacency[current])
                    {
                        dfs(edge.To, distance + 1, phase);
                    }
                    return(true);
                };
                dfs(0, 0, 0);
                dfs(N - 1, 0, 1);

                int fcnt = 0, scnt = 0;

                N.REP(i => {
                    if (distances[0, i] <= distances[1, i])
                    {
                        fcnt++;
                    }
                    else
                    {
                        scnt++;
                    }
                });
                (fcnt > scnt?"Fennec":"Snuke").WL();

                return;
            }