Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC diagnostic ignored "-Wunused-result"
- #include <stdio.h>
- #include <bits/stdc++.h>
- int main() {
- int n, curr; std::cin >> n >> curr;
- std::vector<std::vector<char>> faster(1+n, std::vector<char>(1+n, -1));
- int a, b;
- while (scanf("%d %d", &a, &b) == 2) {
- faster[a][b] = true;
- faster[b][a] = false;
- }
- bool flag = true;
- while (flag) {
- flag = false;
- for (int a = 1; a <= n; ++a) {
- for (int b = 1; b <= n; ++b) {
- if (faster[a][b] > -1) continue;
- for (int c = 1; c <= n; ++c) {
- if (faster[a][c] == 1 && faster[c][b] == 1) {
- faster[a][b] = 1;
- faster[b][a] = 0;
- flag = true;
- break;
- }
- }
- }
- }
- }
- for (int i = 1; i <= n; ++i) {
- if (curr != i && (faster[curr][i] == -1 || faster[curr][i] == 0)) {
- std::cout << "No" << std::endl; return 0;
- }
- }
- std::cout << "Yes" << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement