QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#413816#5655. Train Splittingthesupermarketisgoingtome#AC ✓12ms3852kbC++201.5kb2024-05-18 09:15:442024-05-18 09:15:46

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 09:15:46]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:3852kb
  • [2024-05-18 09:15:44]
  • 提交

answer

/*
 * author:  ADMathNoob
 * created: 05/17/24 20:37:58
 * problem: https://qoj.ac/problem/5655
 */

/*
Comments about problem:


*/

#include <bits/stdc++.h>

using namespace std;

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  auto SolveTestCase = [&]() -> void {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n, vector<int>(n, -1));
    vector<int> deg(n);
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      --x; --y;
      g[x][y] = g[y][x] = i;
      deg[x] += 1;
      deg[y] += 1;
    }
    if (m == n * (n - 1) / 2) {
      vector<int> ret(m, 3);
      for (int i = 2; i < n; i++) {
        ret[g[0][i]] = 1;
        ret[g[1][i]] = 2;
      }
      cout << 3 << '\n';
      for (int i = 0; i < m; i++) {
        cout << ret[i] << " \n"[i == m - 1];
      }
    } else {
      for (int i = 0; i < n; i++) {
        if (deg[i] < n - 1) {
          vector<int> ret(m, 2);
          for (int j = 0; j < n; j++) {
            if (g[i][j] != -1) {
              ret[g[i][j]] = 1;
            }
          }
          cout << 2 << '\n';
          for (int i = 0; i < m; i++) {
            cout << ret[i] << " \n"[i == m - 1];
          }
          return;
        }
      }
    }
  };
  
  {
    int tt;
    cin >> tt;
    for (int qq = 1; qq <= tt; qq++) {
      SolveTestCase();
    }
  }
  
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

2
5 9
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
3 3
1 2
3 1
2 3

output:

2
2 2 1 2 2 1 2 1 2
3
3 1 2

result:

ok OK (2 test cases)

Test #2:

score: 0
Accepted
time: 12ms
memory: 3552kb

input:

100
50 1225
15 33
19 23
14 8
23 26
5 46
22 8
22 13
16 10
20 12
32 16
2 5
36 43
20 33
35 8
4 11
15 43
4 26
33 1
25 36
49 6
11 2
35 11
39 20
24 7
41 2
10 9
40 49
27 17
26 11
49 39
46 27
24 44
26 34
6 27
25 22
9 46
29 43
50 43
2 37
37 10
28 5
14 5
23 28
37 40
10 45
9 26
23 29
35 47
32 21
16 11
9 50
50 ...

output:

3
3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 1 3 3 2 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 ...

result:

ok OK (100 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

554
8 7
1 3
5 3
6 2
3 6
4 6
7 5
8 7
8 7
7 3
3 4
7 1
2 8
1 5
7 6
5 2
10 9
10 1
8 10
4 10
3 10
10 5
6 10
2 10
7 10
10 9
8 7
2 5
1 2
3 6
6 7
8 2
2 7
5 4
10 9
9 6
3 4
5 1
2 5
7 10
3 10
2 6
8 9
1 7
9 8
6 7
1 7
7 5
2 7
3 7
7 9
4 7
7 8
9 8
7 5
4 1
8 6
5 2
4 9
6 1
7 8
2 3
8 7
8 3
7 6
7 1
1 8
4 5
3 2
5 6
8 7...

output:

2
1 2 2 2 2 2 2
2
2 2 1 2 1 2 2
2
1 2 2 2 2 2 2 2 2
2
2 1 2 2 2 2 2
2
2 2 1 2 2 2 2 2 1
2
2 1 2 2 2 2 2 2
2
2 1 2 2 2 1 2 2
2
2 2 1 1 2 2 2
2
1 2 2 2 1 2 2
2
2 2 1 1 2 2 2 2
2
2 1 2 2 2 2 1
2
2 2 2 2 2 2 2 2 1
2
2 2 2 1 1 2 2 2 2
2
2 2 2 2 2 2 2 2 1
2
2 1 2 2 2 2 2 2 2
2
2 2 2 1 2 2 2 2 1
2
1 2 2 2 ...

result:

ok OK (554 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

112
42 41
7 36
24 7
7 42
7 8
15 7
20 7
10 7
7 21
27 7
7 39
40 7
23 7
7 3
7 5
7 35
7 33
7 28
16 7
1 7
7 14
41 7
29 7
12 7
11 7
37 7
25 7
13 7
6 7
7 32
9 7
7 18
4 7
7 22
19 7
34 7
7 2
30 7
31 7
17 7
7 26
7 38
46 45
39 26
23 35
29 7
21 37
27 9
35 10
12 41
40 36
10 9
36 42
41 16
4 16
32 43
13 43
29 45
4...

output:

2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2
2
2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2
2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

result:

ok OK (112 test cases)

Test #5:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

740
3 2
3 2
1 3
3 3
3 1
1 2
2 3
4 3
4 1
1 2
1 3
4 4
2 1
2 3
4 2
4 3
4 3
2 3
1 3
1 4
4 5
3 1
3 2
1 2
4 1
3 4
4 4
1 4
3 4
3 2
1 2
4 6
1 4
3 4
2 4
2 3
2 1
1 3
5 4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
2
2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 1
2
2 2 1 1 2 1 2 1
2
2 2 1 2 2 1 ...

result:

ok OK (852 test cases)

Test #7:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

629
9 10
6 4
5 3
3 2
2 7
1 4
6 7
8 5
3 9
2 6
7 3
9 14
8 1
2 4
9 2
3 1
6 8
9 7
2 3
4 6
6 3
5 9
5 8
4 1
9 8
7 5
9 12
3 1
2 1
5 9
4 9
8 4
2 6
2 4
5 3
9 8
6 7
7 4
3 9
10 10
4 8
10 4
6 5
4 1
7 4
5 3
8 9
2 8
9 4
2 3
8 13
8 2
6 8
1 2
2 7
8 7
4 6
1 5
8 1
6 7
5 3
3 1
5 2
3 8
10 15
7 9
3 8
5 1
9 5
5 4
5 3
7 4...

output:

2
2 2 2 2 1 2 2 2 2 2
2
1 2 2 1 2 2 2 2 2 2 2 1 2 2
2
1 1 2 2 2 2 2 2 2 2 2 2
2
2 2 2 1 2 2 2 2 2 2
2
2 2 1 2 2 2 1 1 2 2 1 2 2
2
2 2 1 2 2 2 2 2 2 1 2 2 2 1 2
2
2 2 2 2 2 2 1 1 2 2
2
2 2 2 2 1 1 1 2 1 2
2
2 2 2 2 2 2 2 1 2 2 2 2 2
2
2 1 2 2 2 1 2 1 2 1 2 2
2
2 1 2 1 2 2 2 2
2
1 2 2 2 2 2 2 2 2
2
2 ...

result:

ok OK (629 test cases)

Test #8:

score: 0
Accepted
time: 2ms
memory: 3544kb

input:

447
11 25
1 11
10 6
3 6
7 2
7 1
9 8
9 4
2 5
3 1
2 1
8 1
8 4
11 7
10 9
9 7
3 2
1 6
1 10
10 11
9 5
6 11
8 5
9 6
3 10
8 6
15 82
6 8
4 3
3 1
14 10
9 8
1 4
7 6
6 4
9 5
12 10
12 9
12 5
2 5
12 13
1 15
3 15
2 15
15 11
12 15
14 8
10 6
3 6
13 5
10 11
5 1
11 8
10 2
2 8
5 4
8 10
13 9
14 7
12 8
3 9
13 11
6 1
5 3...

output:

2
1 2 2 2 1 2 2 2 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2
2
2 2 1 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 2 1 1 1 2 2 1 2 2 2 2 2 2 2 2 1 2
2
2 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 ...

result:

ok OK (447 test cases)

Test #9:

score: 0
Accepted
time: 3ms
memory: 3556kb

input:

348
14 91
1 14
4 7
5 2
14 10
5 3
5 11
6 14
8 7
8 10
6 9
9 8
9 7
13 5
6 2
10 11
10 9
11 7
14 4
7 12
3 7
1 9
10 12
4 6
14 9
12 6
6 10
1 13
10 7
4 1
14 11
4 11
10 5
6 8
11 8
12 8
2 7
8 14
3 10
4 3
1 10
11 12
2 14
12 14
4 5
5 14
7 13
8 5
13 12
9 4
1 7
7 6
7 5
5 9
1 6
8 1
2 8
13 14
12 2
1 3
13 2
10 13
3 ...

output:

3
1 3 2 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 1 3 3 3 3 3 1 3 1 3 3 3 3 3 3 2 3 3 3 1 3 2 3 3 3 3 3 3 3 1 3 3 3 1 1 2 3 2 1 2 3 2 3 3 2 3 3 3 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 2 1 2 3 3
3
3 3 3 2 3 3 3 2 3 2 3 3 1 1 2 3 3 3 3 3 2 1 3 3 3 1 3 3 1 3 3 1 1 2 2 3
2
1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 ...

result:

ok OK (348 test cases)

Test #10:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

146
32 284
19 16
15 10
16 21
3 18
9 24
12 17
18 1
25 23
24 23
22 4
23 18
3 19
30 27
15 7
32 1
20 24
11 26
21 4
23 12
15 18
1 3
1 25
7 9
30 29
19 27
12 20
25 21
27 11
6 27
13 22
5 19
29 2
27 4
27 10
6 8
4 16
18 29
17 21
6 30
12 24
18 12
32 6
22 3
29 13
12 8
22 28
15 17
5 25
24 14
21 18
2 11
3 16
20 1...

output:

2
2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 ...

result:

ok OK (146 test cases)

Test #11:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

146
34 49
10 8
5 28
11 1
9 18
8 32
34 31
26 7
8 23
29 17
33 31
3 9
18 14
3 29
14 33
15 30
33 28
34 2
4 31
9 7
3 28
22 34
23 31
6 30
8 2
1 10
17 34
3 32
5 25
32 2
31 29
8 14
31 28
17 13
19 25
15 32
16 31
26 21
1 24
26 2
14 15
20 9
5 24
27 34
1 3
10 30
22 14
15 31
15 33
6 12
46 58
37 33
6 41
33 12
27 ...

output:

2
2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2
2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2
2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

result:

ok OK (146 test cases)

Test #12:

score: 0
Accepted
time: 4ms
memory: 3596kb

input:

145
36 156
22 15
22 19
35 25
23 22
21 2
36 17
1 24
25 17
9 24
32 22
2 4
31 32
8 22
36 12
36 24
7 18
15 19
28 21
5 30
31 13
10 28
32 19
9 30
19 27
15 24
21 35
2 16
14 16
21 15
6 35
25 8
33 4
3 8
14 32
28 16
18 15
30 26
30 34
23 2
17 20
23 24
34 36
34 8
24 10
31 28
8 24
28 30
18 26
23 13
29 16
31 8
28...

output:

2
2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

result:

ok OK (145 test cases)

Test #13:

score: 0
Accepted
time: 9ms
memory: 3584kb

input:

149
15 105
4 1
10 15
4 7
6 5
2 10
7 9
1 11
10 14
14 12
6 3
9 12
1 6
14 13
5 9
10 1
15 8
4 3
12 4
6 4
9 15
8 1
13 1
15 7
14 3
12 2
10 6
15 2
6 15
12 8
15 13
11 7
14 2
10 9
12 15
5 1
6 7
7 8
13 10
9 11
11 5
3 1
4 15
3 2
5 3
15 1
15 11
7 1
10 11
12 10
11 12
6 11
11 8
4 8
3 7
11 4
4 2
2 5
15 5
6 14
3 12...

output:

3
1 3 3 3 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 3 3 2 3 2 3 3 3 3 2 3 3 1 3 3 3 3 3 1 3 2 3 1 3 1 3 3 3 3 3 3 3 3 2 2 3 3 3 3 3 1 3 1 2 3 3 3 3 3 3 3 2 2 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 2 3 3 3 3 3 1 3 3 3 3 2 3 3 3
3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 ...

result:

ok OK (149 test cases)