Advertisement
Guest User

B4 in LOSH 2016

a guest
Jul 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. int posit[5*1000][5*1000], num, num2, num3, answer, mas[5*1000];
  5. queue<int> many;
  6. int main() {
  7.     //ввод
  8.     cin >> num >> num2 >> num3;
  9.     //cout << num;
  10.     //cout << num2;
  11.     //cout << s;
  12.     int u = num3-1;
  13.     many.push(u);
  14.     for (int i=0,p1,p2;i<num2;i++) {
  15.         //доп перем
  16.         cin >> p1 >> p2;
  17.         int po1 = p1-1;
  18.         int po2 = p2-1;
  19.         posit[po2][po1]=1;
  20.     }
  21.     // b4
  22.     while (many.empty()==0) {
  23.         for (int k=0;k<num;k++) {
  24.             if ((posit[many.front()][k]==1)&&(mas[k]==0)&&(k!=num3-1)) {
  25.                 many.push(k);
  26.                 mas[k] = mas[many.front()] + 1;
  27.                 if (mas[k]>answer) {
  28.                     answer = mas[k];
  29.                 }
  30.             }
  31.         }
  32.         many.pop();
  33.     }
  34.     //вывод
  35.     cout << answer;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement