Submission details
Task:Road network
Sender:team_a
Submission time:2020-10-03 14:57:57 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#60.29 sdetails
#70.29 sdetails
#80.29 sdetails
#90.29 sdetails
#100.29 sdetails
#11ACCEPTED0.01 sdetails

Code

#include <iostream>
using namespace std;

#include <vector>

void visit(long int u, vector<bool> & visited, vector<vector<long int>> G) {
  cerr << u << endl;
  visited[u] = true;
  for (long int v : G[u]) {
    if (not visited[v]) {
      visit(v,visited,G);
    }
  }
}

int main() {
  long int n,m;
  cin >> n >> m;

  vector<vector<long int>> G(n);
  for (long int i=0; i<m; ++i) {
    long int x,y;
    cin >> x >> y;
    G[x-1].push_back(y-1);
  }

  bool done = false;
  for (int u=0; u<n and not done; ++u) {
    vector<bool> visited(n,0);
    visit(u,visited,G);

    long int v = 0;
    while (visited[v] and v<n-1) v++;

    if (not visited[v]) {
      done = true;
      cout << "NO" << endl << u+1 << ' ' << v+1 << endl;
    }
  }
  if (not done) cout << "YES" << endl;
}

Test details

Test 1

Verdict: ACCEPTED

input
10 20
8 1
9 5
6 10
6 1
...

correct output
NO
7 1

user output
NO
7 1

Error:
0
3
8
4
2
1
5
9
7
6
1
3
8
4
2
9
7
0
6
5
2
1
3
8
4
9
7
0
6
5
3
8
4
2
1
5
9
0
7
6
4
2
1
3
8...

Test 2

Verdict: ACCEPTED

input
10 20
2 10
10 6
8 5
3 8
...

correct output
NO
1 2

user output
NO
1 2

Error:
0

Test 3

Verdict: ACCEPTED

input
10 20
10 2
1 5
8 3
5 6
...

correct output
NO
9 1

user output
NO
9 1

Error:
0
4
5
3
7
2
1
6
8
9
1
6
7
2
0
4
5
3
9
8
2
0
4
5
3
7
9
1
6
8
3
7
2
0
4
5
9
1
6
8
4
5
3
7
2...

Test 4

Verdict: ACCEPTED

input
10 20
9 6
10 4
7 2
10 5
...

correct output
NO
6 1

user output
NO
6 1

Error:
0
8
5
2
3
4
6
1
7
9
1
4
6
0
8
5
2
3
7
9
2
3
4
6
1
0
8
5
7
9
3
4
6
1
0
8
5
2
7
9
4
6
1
0
8...

Test 5

Verdict: ACCEPTED

input
10 20
5 9
10 2
3 5
7 4
...

correct output
YES

user output
YES

Error:
0
5
2
4
8
1
6
3
9
7
1
6
3
8
0
5
2
4
7
9
2
4
8
1
6
3
0
5
9
7
3
1
6
0
5
2
4
8
7
9
4
8
1
6
3...

Test 6

Verdict:

input
100000 200000
64780 62469
32706 84268
37795 14893
23995 68041
...

correct output
NO
40590 1

user output
(empty)

Error:
0
1650
8549
54027
49578
82412
49863
35696
88036
99481
56150
41851
25861
65616
51289
95886...

Test 7

Verdict:

input
100000 200000
74725 92399
25141 53472
70762 85785
47091 71621
...

correct output
NO
96983 1

user output
(empty)

Error:
0
92897
34109
54275
14574
77381
83368
94698
26041
72092
61175
13035
30301
58803
20988
1897...

Test 8

Verdict:

input
100000 200000
50342 88741
55031 42206
24989 54546
666 39964
...

correct output
NO
1 68638

user output
(empty)

Error:
0
67923
56065
36548
91245
31229
92000
45003
20433
61295
45734
53073
50491
93288
19947
4857...

Test 9

Verdict:

input
100000 200000
51243 54643
90493 3012
62110 9430
5809 45601
...

correct output
NO
48024 1

user output
(empty)

Error:
0
14411
20581
69470
55687
79181
99769
70791
57780
75682
96087
1045
33930
42841
7542
25530...

Test 10

Verdict:

input
100000 200000
5524 49109
87052 72192
46434 18442
67624 38661
...

correct output
YES

user output
(empty)

Error:
0
23151
46301
3945
13580
43902
655
96971
72212
72460
96962
99883
5528
42299
15256
38766
70...

Test 11

Verdict: ACCEPTED

input
7 10
1 2
2 1
1 4
5 4
...

correct output
NO
2 3

user output
NO
1 3

Error:
0
1
4
3