Exemple #1
0
        public override void Do()
        {
            var n   = reader.ReadInt();
            var cnt = new int[n + 1];
            var m   = reader.ReadInt();

            while (m-- > 0)
            {
                var a = reader.ReadInt();
                var b = reader.ReadInt();
                ++cnt[a];
                ++cnt[b];
            }
            for (int i = 1; i <= n; ++i)
            {
                if (cnt[i] % 2 == 1)
                {
                    writer.WriteLine("NO");
                    return;
                }
            }
            writer.WriteLine("YES");
        }
Exemple #2
0
        public override void Do()
        {
            var h = reader.ReadInt();
            var w = reader.ReadInt();
            var k = reader.ReadInt();
            var s = new string[h];

            for (int i = 0; i < h; ++i)
            {
                s[i] = reader.ReadString();
            }
            var dx     = new int[] { 0, 1, 0, -1 };
            var dy     = new int[] { 1, 0, -1, 0 };
            var res    = Create2DArray <int>(h, w);
            int answer = int.MaxValue;

            for (int i = 0; i < h; ++i)
            {
                for (int j = 0; j < w; ++j)
                {
                    if (s[i][j] == 'S')
                    {
                        res[i][j] = 1;
                        var q = new Queue <int>();
                        q.Enqueue(1000 * i + j);
                        while (q.Count > 0)
                        {
                            var dq       = q.Dequeue();
                            var qi       = dq / 1000;
                            var qj       = dq % 1000;
                            var toborder = Math.Min(Math.Min(qi, qj), Math.Min(h - 1 - qi, w - 1 - qj));
                            if (toborder % k > 0)
                            {
                                toborder = toborder / k + 1;
                            }
                            else
                            {
                                toborder = toborder / k;
                            }
                            answer = Math.Min(answer, 1 + toborder);
                            if (res[qi][qj] <= k)
                            {
                                for (int l = 0; l < 4; ++l)
                                {
                                    if (qi + dx[l] >= 0 && qj + dy[l] >= 0 && qi + dx[l] < h && qj + dy[l] < w)
                                    {
                                        if (res[qi + dx[l]][qj + dy[l]] == 0 && s[qi + dx[l]][qj + dy[l]] == '.')
                                        {
                                            res[qi + dx[l]][qj + dy[l]] = 1 + res[qi][qj];
                                            q.Enqueue((qi + dx[l]) * 1000 + qj + dy[l]);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
            writer.WriteLine(answer);
        }
Exemple #3
0
        public override void Do()
        {
            var n      = reader.ReadInt();
            var nodes  = new List <int> [n];
            var was    = new bool[n];
            var dead   = new bool[n];
            var parent = new int[n];

            for (int i = 0; i < n; ++i)
            {
                nodes[i] = new List <int>();
            }
            for (int i = 0; i < n - 1; ++i)
            {
                var a = reader.ReadInt() - 1;
                var b = reader.ReadInt() - 1;
                nodes[a].Add(b);
                nodes[b].Add(a);
            }
            var st = new Stack <int>();

            st.Push(0);
            was[0] = true;
            while (st.Count > 0)
            {
                var nd = st.Pop();
                foreach (var cn in nodes[nd])
                {
                    if (!was[cn])
                    {
                        was[cn]    = true;
                        parent[cn] = nd;
                        st.Push(cn);
                    }
                }
            }
            st.Push(0);
            was    = new bool[n];
            was[0] = true;
            while (st.Count > 0)
            {
                var nd = st.Peek();
                foreach (var cn in nodes[nd])
                {
                    if (!was[cn])
                    {
                        was[cn] = true;
                        st.Push(cn);
                    }
                }
                if (nd == st.Peek())
                {
                    st.Pop();
                    int alive = 0;
                    foreach (var cn in nodes[nd])
                    {
                        if (cn != parent[nd])
                        {
                            alive += dead[cn] ? 0 : 1;
                        }
                    }
                    if (alive > 1)
                    {
                        writer.WriteLine("First");
                        return;
                    }
                    else if (alive == 1)
                    {
                        dead[nd] = true;
                    }
                }
            }
            writer.WriteLine(!dead[0] ? "First" : "Second");
        }