ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1837. Isenbaev's Number

WA #11
Posted by Alexander31 23 Aug 2014 05:41
I got WA 11. Can anybody give me test?
Here is my solution:

#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int minimum(int arr[300][300], map < int, string > Num, map < string, int >L, int cur)
{

int min_ = 100499;

for (int i = 0; i < cur; ++i)

if (arr[cur][i] && L[Num[i]] < min_)

min_ = L[Num[i]];

return min_;

}

void Level_up(map < string, int >Nam, map < int, string > Num, map < string, int >&Lev, int sz, int arr[300][300])
{

for (int i = 0; i < sz; ++i) {

int level = Lev[Num[i]];

if (!level && Num[i] != "Isenbaev")    // Если имя ещё не встречалось

Lev[Num[i]] = level = minimum(arr, Num, Lev, sz) + 1;

for (int j = 0; j < sz; ++j)

if (i != j && arr[i][j])

if ((Num[j] != "Isenbaev" && Lev[Num[j]] == 0) || Lev[Num[j]] > level + 1)

Lev[Num[j]] = level + 1;

}

}

int main()
{

int N;

string f;

string s;

string t;

string P = "Isenbaev";

map < string, int >Name;

map < int, string > Number;

int count = 1;

Name[P] = count++;

Number[0] = P;

int arr[300][300];

map < string, int >Level;

bool flag = false;

cin >> N;

for (int i = 0; i < N; ++i) {

cin >> f >> s >> t;

if (f == P || s == P || t == P)
flag = true;

if (!Name[f])

Name[f] = count++;

if (!Name[s])

Name[s] = count++;

if (!Name[t])

Name[t] = count++;

Number[Name[f] - 1] = f;

Number[Name[s] - 1] = s;

Number[Name[t] - 1] = t;

arr[Name[f] - 1][Name[s] - 1] = arr[Name[s] - 1][Name[f] - 1] =    arr[Name[f] - 1][Name[t] - 1] = arr[Name[t] - 1][Name[f] - 1] = arr[Name[s] - 1][Name[t] - 1] = arr[Name[t] - 1][Name[s] - 1] = 1;

}

Level[P] = 0;

Level_up(Name, Number, Level, count - 1, arr);

for (map < string, int >::iterator it = Level.begin(); it != Level.end(); ++it) {

if (flag || !flag && it->first != P) {

cout << it->first << " ";

if (it->first != P)

if (it->second < count)

cout << it->second << endl;

else
cout << "undefined" << endl;

else
cout << it->second << endl;

}

}

return 0;

}

Sorry, for the my code and my English.

Edited by author 24.08.2014 03:07