Submission details
Task:Järjestys
Sender:jubidubi
Submission time:2025-09-06 19:16:41 +0300
Language:C++ (C++11)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 4, 5details
#2ACCEPTED0.00 s1, 4, 5details
#3ACCEPTED0.00 s1, 4, 5details
#4ACCEPTED0.01 s1, 4, 5details
#5ACCEPTED0.00 s1, 4, 5details
#6ACCEPTED0.00 s1, 2, 4, 5details
#7ACCEPTED0.01 s1, 3, 4, 5details
#8ACCEPTED0.01 s1, 4, 5details
#9--2, 4, 5details
#10--3, 4, 5details
#11--4, 5details
#12--4, 5details
#13--4, 5details
#14--4, 5details
#15--2, 5details
#16--3, 5details
#17--5details
#18--5details
#19--5details
#20--5details
#21--5details
#22--5details

Compiler report

input/code.cpp: In function 'void solve(int)':
input/code.cpp:14:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |   if (path.size() == n) return;
      |       ~~~~~~~~~~~~^~~~
input/code.cpp:19:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |     if (path.size() == n) return;
      |         ~~~~~~~~~~~~^~~~
input/code.cpp: In function 'int main()':
input/code.cpp:54:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |       if (path.size() == n) break;
      |           ~~~~~~~~~~~~^~~~
input/code.cpp:58:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-comp...

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 505;
vector<int> v[N];
bool visited[N];
vector<int> path;

int n;
void solve(int x) {
  path.push_back(x);
  visited[x] = 1;
  if (path.size() == n) return;

  for (int nx : v[x]) {
    if (visited[nx]) continue;
    solve(nx);
    if (path.size() == n) return;
  }
  path.pop_back();
  visited[x] = 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int qqq;
  cin >> qqq;
  while (qqq--) {
    cin >> n;

    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

    path.clear();
    for (int i = 0; i < n; ++i) {
      v[i].clear();
      visited[i] = 0;
    }

    for (int a = 0; a < n; ++a) {
      for (int b = 0; b < n; ++b) {
        if (a == b) continue;
        if (p[a].second <= p[b].first) v[a].push_back(b);
      }
    }

    int s = -1;
    for (int i = 0; i < n; ++i) {
      solve(i);

      if (path.size() == n) break;
      for (int j = 0; j < n; ++j) visited[j] = 0;
    }

    if (path.size() != n) {
      cout << "NO" << endl;
      continue;
    }

    cout << "YES" << endl;
    for (int x : path) {
      cout << p[x].first << " " << p[x].second << endl;
    }
  }
}

Test details

Test 1

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
1
74 75
1
100 43
...

correct output
YES
74 75
YES
100 43
YES
...

user output
YES
74 75
YES
100 43
YES
...
Truncated

Test 2

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
2
80 54
51 61
2
...

correct output
YES
51 61
80 54
YES
2 64
...

user output
YES
51 61
80 54
YES
2 64
...
Truncated

Test 3

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
3
3 74
91 45
100 24
...

correct output
YES
3 74
100 24
91 45
YES
...

user output
YES
3 74
91 45
100 24
YES
...
Truncated

Test 4

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
4
88 50
62 41
12 86
...

correct output
YES
12 86
88 50
62 41
66 93
...

user output
YES
12 86
88 50
62 41
66 93
...
Truncated

Test 5

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
5
82 80
80 92
5 22
...

correct output
YES
5 22
94 13
82 80
80 92
...

user output
YES
5 22
82 80
80 92
94 13
...
Truncated

Test 6

Group: 1, 2, 4, 5

Verdict: ACCEPTED

input
100
5
34 38
26 30
1 6
...

correct output
YES
1 6
12 22
26 30
34 38
...

user output
YES
1 6
12 22
26 30
34 38
...
Truncated

Test 7

Group: 1, 3, 4, 5

Verdict: ACCEPTED

input
100
5
50 40
28 25
51 7
...

correct output
YES
51 7
50 40
47 1
17 11
...

user output
YES
50 40
51 7
28 25
47 1
...
Truncated

Test 8

Group: 1, 4, 5

Verdict: ACCEPTED

input
100
5
2 2
2 1
1 1
...

correct output
YES
1 2
2 1
2 1
1 1
...

user output
YES
2 2
2 1
1 1
1 2
...
Truncated

Test 9

Group: 2, 4, 5

Verdict:

input
100
100
175870020 296379324
248160539 883842002
21934885 781732852
...

correct output
NO
YES
4976156 6890135
10553287 11923223
14617057 17728163
...

user output
(empty)

Test 10

Group: 3, 4, 5

Verdict:

input
100
100
447597377 314433951
700232436 691277009
937268439 708165426
...

correct output
YES
998963839 391778929
995772196 257222033
995754704 553123757
994629465 247775824
...

user output
(empty)

Test 11

Group: 4, 5

Verdict:

input
100
100
1 1
1 2
2 1
...

correct output
YES
1 2
2 1
1 2
2 2
...

user output
(empty)

Test 12

Group: 4, 5

Verdict:

input
100
100
7 1
6 3
10 9
...

correct output
YES
6 7
7 8
9 10
10 10
...

user output
(empty)

Test 13

Group: 4, 5

Verdict:

input
100
100
51 5
85 77
91 84
...

correct output
YES
100 24
100 25
100 3
100 6
...

user output
(empty)

Test 14

Group: 4, 5

Verdict:

input
100
100
823828194 863717310
593641073 340054211
420481158 965069109
...

correct output
YES
999289319 634855378
996775156 433726648
983657502 55234695
981890636 112877413
...

user output
(empty)

Test 15

Group: 2, 5

Verdict:

input
100
500
88724450 89315226
266915464 267648621
189301651 189661541
...

correct output
YES
764920 1459946
1936195 2832987
3691481 4085931
4991808 5840928
...

user output
(empty)

Test 16

Group: 3, 5

Verdict:

input
100
500
763682761 317584504
756010800 260162861
435911339 78070399
...

correct output
YES
998768285 3307355
998714926 628486754
997115613 820932481
993320616 554600893
...

user output
(empty)

Test 17

Group: 5

Verdict:

input
100
500
2 2
2 1
1 2
...

correct output
YES
1 2
2 2
2 1
1 2
...

user output
(empty)

Test 18

Group: 5

Verdict:

input
100
500
10 6
10 10
9 10
...

correct output
YES
2 3
3 4
4 5
5 6
...

user output
(empty)

Test 19

Group: 5

Verdict:

input
100
500
85 87
89 70
70 92
...

correct output
YES
96 97
100 67
100 10
100 97
...

user output
(empty)

Test 20

Group: 5

Verdict:

input
100
500
861154169 119512584
569086662 606567153
288230434 322196278
...

correct output
YES
999945324 969534372
999738857 240617694
999244114 722161553
999207839 557351400
...

user output
(empty)

Test 21

Group: 5

Verdict:

input
100
500
116439250 401518028
280329609 193466222
674040956 209050570
...

correct output
NO
YES
773701149 773852119
987509190 315670966
977413249 510418200
...

user output
(empty)

Test 22

Group: 5

Verdict:

input
100
500
934181189 942499518
684836806 395802802
957884803 570946201
...

correct output
YES
999772640 505132174
999111650 140844643
999028633 888134186
999020109 291046771
...

user output
(empty)