Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int posit[5*1000][5*1000], num, num2, num3, answer, mas[5*1000];
- queue<int> many;
- int main() {
- //ввод
- cin >> num >> num2 >> num3;
- //cout << num;
- //cout << num2;
- //cout << s;
- int u = num3-1;
- many.push(u);
- for (int i=0,p1,p2;i<num2;i++) {
- //доп перем
- cin >> p1 >> p2;
- int po1 = p1-1;
- int po2 = p2-1;
- posit[po2][po1]=1;
- }
- // b4
- while (many.empty()==0) {
- for (int k=0;k<num;k++) {
- if ((posit[many.front()][k]==1)&&(mas[k]==0)&&(k!=num3-1)) {
- many.push(k);
- mas[k] = mas[many.front()] + 1;
- if (mas[k]>answer) {
- answer = mas[k];
- }
- }
- }
- many.pop();
- }
- //вывод
- cout << answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement