ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1195. Ouths and Crosses

WA #13
Posted by tupica 20 Feb 2008 03:04
I can't find my mistake...
Re: WA #13
Posted by Astor 28 Feb 2008 12:56
using System;
using System.Collections;

namespace граф_1
{

    class Class1
    {

        [STAThread]
        static void Main(string[] args)

            {
                //читаем
                int n = int.Parse(Console.ReadLine());
                int m = int.Parse(Console.ReadLine());
                int[,] graf = new int[n,n];
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        graf[i, j] = 0;
                for (int i = 0; i < m; i++)
                {
                    string s = Console.ReadLine();
                    string[] s1 = s.Split(' ');
                    graf[int.Parse(s1[0]) - 1, int.Parse(s1[1]) - 1] = 1;
                    graf[int.Parse(s1[1]) - 1, int.Parse(s1[0]) - 1] = 1;
                }
                //Обходим все вершины
                int[] part = new int[n];
                Queue q = new Queue(n);
                bool[] discovered = new bool[n];
                for (int i = 0; i < n; i++)
                {
                    part[i] = 0;
                    discovered[i] = false;
                }
                part[0] = 1;
                bool b = true;
                //определяем, к какой доле они принадлежат
                q.Enqueue(0);
                discovered[0] = true;
                while(q.Count != 0)
                {
                    int v = (int) q.Dequeue();
                    for(int i = 0; i < n; i++)
                    {
                        if(graf[v,i] == 1)
                        {
                            if (!discovered[i])
                            {
                                discovered[i] = true;
                                q.Enqueue(i);
                            }
                            if (part[i] != part[v])
                                part[i] = -part[v];
                            else
                                b = false;
                        }
                    }
                    if (!b)
                        break;
                }
                if (b)
                {
                    for (int i = 0; i < n; i++)
                        if(part[i]==1)
                            Console.WriteLine(i+1);
                }
                else
                    Console.WriteLine(0);

            }
        }
    }