ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1888. Стаж пилотов

WA 6
Послано Roman Furko 29 окт 2011 23:13
Please help me!
I cannot find mistake in my solution =(
#include <iostream>
#include <vector>
#include <memory.h>
#include <string>
#include <map>
#include <set>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for ((i) = (a); i < (b); ++i)
#define rep(i,n) FOR(i,0,n)
#define FON(i,a,b) for ((i) = (b); i >= (a); --i)
#define repn(i,n) FON(i,0,n)
#define ll long long
#define dd double
#define pb push_back
#define mp make_pair
#define inf 10000000000LL
#define y1 aksld

int frabs(int x)
 {
  if (x < 0) x = -x;
  return x;
 }


int a[100][100] = {0};
int pp[100] = {0};
int n,p,i,j,x,y,yk2;
int pr[100];
int prd[100];


int f(int x)
 {
  if (pr[x] == x) return x;
   else {
          pr[x] = f(pr[x]);
          return pr[x];
        }
 }

void un(int x, int y)
 {
  if (x>y) pr[x] = y;
  else pr[y] = x;
 }

int GO(int x)
 {
   int i;
   FOR(i,0,n)
     if (a[x][i])
             {
              if (pp[i] == 0)
                {
                 pp[i] = pp[x] + 1;
                 if (pp[i] == 3) pp[i] = 1;
                 GO(i);
                }
               else if (pp[i] == pp[x])
                {
                 cout<<-1<<endl;
                 exit(0);
                }
             }
 }

int tin[100],tout[100],timer = 0;

bool preeed(int x, int y)
 {
    return (tin[x] < tin[y] && tout[x] > tout[y]);
 }

bool used[100];

void FPR(int x)
 {
    tin[x] = ++timer;
    used[x] = true;
    int i;
    FOR(i,0,n)
      if (a[x][i] && used[i] == false) FPR(i);

    tout[x] = ++timer;
 }

bool DFS(int x)
 {
    int i;
    bool ok = true;
    FOR(i,0,n)
       if (a[x][i] && preeed(x,i))
        {
           pp[i] = pp[x] + 1;
           if (DFS(i)) ok = true;
            else if (pp[x] > 2)
                 {
                   pp[i] = pp[x] - 1;
                   if (DFS(i)) ok = true;
                    else
                     {
                      ok = false;
                      break;
                     }
                 }
        }
       else if (a[x][i])
        {
           if (frabs(pp[i]-pp[x]) != 1)
            {
             ok = false;
             break;
            }
        }
   return ok;
 }

int main()
{
  cin >> p >> n;
  FOR(i,0,p)
    {
     cin >> x >> y;
     --x; --y;
     a[x][y] = 1;
     a[y][x] = 1;
    }

  memset(used,false,sizeof(used));

  FOR(i,0,n)
   pr[i] = i;

  FOR(i,0,n)
   {
      FOR(j,0,n)
        if (a[i][j] && f(i) != f(j)) un(f(i),f(j));
   }

  bool ok = false;
  FOR(i,0,n)
     if (f(i) != f(0))
       {
          ok = true;
          break;
       }

  FOR(i,0,n)
    {
       if (!pp[i]) {
                    pp[i] = 1;
                    GO(i);
                   }
    }

  if (ok)
        {
           FOR(i,0,n)
             if (f(i) != f(0)) pp[i] = 50-pp[i]+1;
           int mx = 0;
           FOR(i,0,n)
             FOR(j,0,n)
              if (frabs(pp[i]-pp[j])>mx) mx = frabs(pp[i]-pp[j]);
           cout<<mx<<endl;
           FOR(i,0,n)
               cout<<pp[i]<<" ";
           cout<<endl;
        }
     else
       {
           memset(pp,0,sizeof(pp));
           memset(prd,0,sizeof(prd));

           FOR(i,0,n)
             if (!used[i]) FPR(i);

           FOR(i,0,n)
             if (!pp[i])
               {
                  pp[i] = 1;
                  DFS(i);
               }
           int mx = 0;
           FOR(i,0,n)
             FOR(j,0,n)
               if (frabs(pp[i]-pp[j])>mx) mx = frabs(pp[i]-pp[j]);
           cout<<mx<<endl;
           FOR(i,0,n)
               cout<<pp[i]<<" ";
           cout<<endl;

       }
}

If u cant find mistake give me some tests!
Thx a lot!
Sorry for my bad english

Edited by author 29.10.2011 23:14
Re: WA 6
Послано bsu.mmf.team 31 окт 2011 22:04
Your program fails on this test:
3 4
3 1
1 2
2 4

Edited by author 31.10.2011 22:04
Re: WA 6
Послано ffbh 5 апр 2017 09:55
thank you very much!!!!!!!!