QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78011#1824. Special Cyclehos_lyricAC ✓8ms4188kbC++146.5kb2023-02-16 13:36:432023-02-16 13:36:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-16 13:36:46]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:4188kb
  • [2023-02-16 13:36:43]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


// sz: size of the matching
// mate[u]: matching mate of u or -1
// need[u]: every max matching contains u? (call run(true))
struct MaxMatch {
  int n, sz;
  vector<vector<int>> graph;
  vector<int> mate, need;
  MaxMatch() {}
  MaxMatch(int n_) : n(n_), graph(n_) {}
  void ae(int u, int v) {
    assert(0 <= u); assert(u < n);
    assert(0 <= v); assert(v < n);
    if (u != v) {
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
  }

  vector<int> ts, ps;
  vector<pair<int, int>> fs;
  int root(int u) {
    return (ts[u] != sz || !~ps[u]) ? u : (ps[u] = root(ps[u]));
  }
  void rematch(int u, int v) {
    const int w = mate[u];
    mate[u] = v;
    if (~w && mate[w] == u) {
      if (~fs[u].second) {
        rematch(fs[u].first, fs[u].second);
        rematch(fs[u].second, fs[u].first);
      } else {
        mate[w] = fs[u].first;
        rematch(fs[u].first, w);
      }
    }
  }
  int augment(int src) {
    std::queue<int> que;
    ts[src] = sz;
    ps[src] = -1;
    fs[src] = make_pair(-1, -1);
    que.push(src);
    for (; !que.empty();) {
      int u = que.front();
      que.pop();
      for (const int v : graph[u]) if (v != src) {
        if (mate[v] == -1) {
          mate[v] = u;
          rematch(u, v);
          return 1;
        }
        if (ts[v] == sz) {
          int x = root(u), y = root(v), z = src;
          if (x == y) continue;
          for (; x != src || y != src; x = root(fs[mate[x]].first)) {
            if (y != src) swap(x, y);
            if (fs[x].first == u && fs[x].second == v) {
              z = x;
              break;
            }
            fs[x] = make_pair(u, v);
          }
          for (const int r : {root(u), root(v)}) {
            for (int w = r; w != z; w = root(fs[mate[w]].first)) {
              ts[w] = sz;
              ps[w] = z;
              que.push(w);
            }
          }
        } else if (ts[mate[v]] != sz) {
          fs[v] = make_pair(-1, -1);
          ts[mate[v]] = sz;
          ps[mate[v]] = v;
          fs[mate[v]] = make_pair(u, -1);
          que.push(mate[v]);
        }
      }
    }
    return 0;
  }
  void run(bool buildNeed = false) {
    sz = 0;
    mate.assign(n, -1);
    ts.assign(n, -1);
    ps.assign(n, -1);
    fs.assign(n, make_pair(-1, -1));
    for (int u = 0; u < n; ++u) if (!~mate[u]) sz += augment(u);
    if (buildNeed) {
      for (int u = 0; u < n; ++u) if (!~mate[u]) augment(u);
      need.resize(n);
      for (int u = 0; u < n; ++u) need[u] = (~mate[u] && ts[u] != sz) ? 1 : 0;
    }
  }
};


int N, M, K;
vector<int> A, B;

vector<int> solve() {
  int id = 0;
  vector<vector<int>> idss(N);
  vector<pair<int, int>> edges(K);
  for (int i = 0; i < K; ++i) {
    const int x = id++;
    const int y = id++;
    idss[A[i]].push_back(x);
    idss[B[i]].push_back(y);
    edges[i] = make_pair(x, y);
  }
  vector<int> spe(N, 0);
  for (int u = 0; u < N; ++u) {
    spe[u] = idss[u].size();
    // not used
    if (spe[u] == 0) {
      idss[u].push_back(id++);
      idss[u].push_back(id++);
    }
  }
  vector<int> tr(id, -1);
  for (int u = 0; u < N; ++u) {
    for (const int x : idss[u]) {
      tr[x] = u;
    }
  }
// cerr<<"idss = "<<idss<<endl;
  
  for (int ban = 0; ban < K; ++ban) {
    MaxMatch mxm(id);
    for (int i = 0; i < K; ++i) if (i != ban) {
      mxm.ae(edges[i].first, edges[i].second);
    }
    for (int i = K; i < M; ++i) if (spe[A[i]] < 2 && spe[B[i]] < 2) {
      for (const int x : idss[A[i]]) for (const int y : idss[B[i]]) {
        mxm.ae(x, y);
      }
    }
    for (int u = 0; u < N; ++u) if (idss[u].size() == 2) {
      mxm.ae(idss[u][0], idss[u][1]);
    }
    mxm.run();
    if (2 * mxm.sz == id) {
      vector<int> mate(id, -1);
      for (int u = 0; u < N; ++u) if (idss[u].size() == 2) {
        mate[idss[u][0]] = idss[u][1];
        mate[idss[u][1]] = idss[u][0];
      }
      // overwrite vertex with two special edges
      for (int i = 0; i < K; ++i) {
        mate[edges[i].first] = edges[i].second;
        mate[edges[i].second] = edges[i].first;
      }
// cerr<<"mate = "<<mate<<endl;
// cerr<<"mxm.mate = "<<mxm.mate<<endl;
      vector<int> cyc;
      for (int x = edges[ban].first; ; ) {
        cyc.push_back(tr[x]);
        // new matching
        x = mxm.mate[x];
        assert(~x);
        
        cyc.push_back(tr[x]);
        // original matching
        x = mate[x];
        assert(~x);
        
        if (x == edges[ban].first) {
          break;
        }
      }
// cerr<<"cyc = "<<cyc<<endl;
      vector<int> ans;
      for (const int u : cyc) {
        for (int j = 0; j < (int)ans.size(); ++j) {
          if (ans[j] == u) {
            ans.erase(ans.begin() + j, ans.end());
            break;
          }
        }
        ans.push_back(u);
      }
      return ans;
    }
  }
  return {};
}

int main() {
  for (; ~scanf("%d%d%d", &N, &M, &K); ) {
    A.resize(M);
    B.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d", &A[i], &B[i]);
      --A[i];
      --B[i];
    }
    
    const auto ans = solve();
    if (!ans.empty()) {
      printf("%d\n", (int)ans.size());
      for (const int u : ans) {
        printf("%d\n", u + 1);
      }
    } else {
      puts("-1");
    }
#ifdef LOCAL
cerr<<"========"<<endl;
#endif
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3716kb

input:

8 10 3
1 2
4 5
7 8
2 3
3 4
1 4
5 6
6 7
5 8
3 8

output:

8
1
4
5
6
7
8
3
2

result:

ok OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3468kb

input:

4 6 3
1 2
1 3
1 4
2 3
3 4
2 4

output:

-1

result:

ok OK: both impossible

Test #3:

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

input:

66 88 22
3 4
6 11
9 10
12 17
15 16
18 23
21 22
24 29
27 28
30 35
33 34
36 41
39 40
42 47
45 46
48 53
51 52
54 59
57 58
60 65
63 64
5 66
1 2
2 3
1 3
4 5
5 6
4 6
7 8
8 9
7 9
10 11
11 12
10 12
13 14
14 15
13 15
16 17
17 18
16 18
19 20
20 21
19 21
22 23
23 24
22 24
25 26
26 27
25 27
28 29
29 30
28 30
31...

output:

22
6
5
66
65
60
59
54
53
48
47
42
41
36
35
30
29
24
23
18
17
12
11

result:

ok OK

Test #4:

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

input:

57 95 32
44 57
2 7
8 48
4 38
17 48
31 49
43 56
38 50
13 15
23 44
8 27
48 54
5 47
25 47
47 51
23 28
1 5
43 46
5 8
25 28
3 10
35 46
10 34
20 23
2 31
26 32
9 37
19 22
16 52
11 26
23 38
16 42
5 28
40 50
30 56
36 39
28 57
42 44
1 45
5 56
12 45
7 9
12 40
3 50
17 27
12 38
40 46
12 25
9 42
20 21
45 49
11 24...

output:

9
13
45
42
16
52
11
26
32
15

result:

ok OK

Test #5:

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

input:

98 93 36
15 81
19 93
57 65
46 80
34 47
9 25
58 78
13 61
8 18
73 90
2 39
5 82
49 64
4 62
40 85
14 79
47 73
10 83
43 65
30 59
80 81
40 41
95 98
3 92
15 55
4 98
31 37
74 86
46 69
24 27
70 79
21 28
12 83
60 84
52 98
17 96
83 93
6 32
53 96
29 66
50 66
27 71
40 53
81 94
14 18
63 98
10 59
10 22
8 25
19 85
...

output:

7
8
5
82
24
27
42
18

result:

ok OK

Test #6:

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

input:

146 277 99
43 110
11 123
76 90
60 88
107 129
38 129
23 49
9 56
125 144
89 138
31 88
74 136
46 126
107 122
31 53
8 18
25 42
12 123
3 128
68 121
28 88
35 65
24 52
24 53
74 108
28 79
85 94
64 113
6 77
128 136
111 146
41 136
14 111
88 125
41 83
48 145
13 29
13 33
69 96
46 130
11 92
31 58
65 112
96 104
1...

output:

13
11
92
102
116
37
101
44
34
54
80
1
12
123

result:

ok OK

Test #7:

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

input:

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

output:

7
10
13
24
8
9
6
19

result:

ok OK

Test #8:

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

input:

60 97 23
45 52
18 55
1 53
5 35
37 47
25 43
11 55
5 41
36 59
26 40
38 39
21 51
30 32
27 60
46 51
21 50
19 35
20 26
24 31
4 25
8 37
5 33
33 49
33 46
53 59
18 22
21 37
19 41
11 59
25 52
23 54
22 36
31 55
38 45
28 56
41 45
7 27
24 30
21 57
11 56
15 56
6 22
42 56
15 39
48 53
5 29
31 41
2 31
17 27
5 36
7 ...

output:

12
45
38
39
15
56
11
55
18
60
27
17
52

result:

ok OK

Test #9:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

62 41 13
12 48
6 26
37 57
2 23
11 62
42 45
24 59
50 51
16 55
41 60
23 54
12 45
6 51
5 21
20 51
25 42
13 26
37 62
19 61
5 40
7 42
6 37
22 28
46 49
10 23
16 31
44 62
24 57
21 29
15 18
33 61
29 57
21 41
23 27
40 42
5 49
32 55
11 37
44 46
40 59
34 62

output:

11
37
11
62
44
46
49
5
40
59
24
57

result:

ok OK

Test #10:

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

input:

6 8 1
1 4
3 6
1 6
1 2
3 5
5 6
4 6
3 4

output:

3
1
6
4

result:

ok OK

Test #11:

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

input:

8 17 6
4 7
1 5
3 6
5 7
3 5
3 4
2 4
1 6
2 6
2 7
6 7
4 6
3 8
1 2
7 8
1 3
2 8

output:

-1

result:

ok OK: both impossible

Test #12:

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

input:

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

output:

-1

result:

ok OK: both impossible

Test #13:

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

input:

23 14 3
1 20
5 10
21 22
4 23
8 14
11 23
12 14
17 20
10 14
2 13
1 23
1 15
1 9
5 15

output:

-1

result:

ok OK: both impossible

Test #14:

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

input:

3 2 1
2 3
1 3

output:

-1

result:

ok OK: both impossible

Test #15:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

17 84 25
11 14
4 16
5 16
4 8
1 2
11 13
8 12
7 11
11 12
6 12
8 14
1 10
9 16
7 9
13 14
15 16
1 16
3 14
7 14
5 10
3 6
2 14
6 7
15 17
2 11
2 6
16 17
2 13
4 12
1 13
4 11
1 7
12 15
3 17
12 16
9 12
11 15
13 17
10 16
2 4
6 13
6 15
10 14
3 4
1 14
4 7
2 8
5 17
1 12
5 6
10 13
3 16
7 12
9 17
4 13
4 10
9 13
8 16...

output:

-1

result:

ok OK: both impossible

Test #16:

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

input:

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

output:

-1

result:

ok OK: both impossible

Test #17:

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

input:

10 15 5
2 3
6 7
9 10
4 8
1 5
7 8
8 9
3 4
4 5
5 6
1 2
3 10
2 7
1 9
6 10

output:

8
2
1
5
6
7
8
4
3

result:

ok OK

Test #18:

score: 0
Accepted
time: 6ms
memory: 4140kb

input:

150 10783 2
22 139
31 85
18 37
10 73
62 129
14 22
33 68
31 140
88 136
39 58
20 40
26 32
64 77
20 79
72 126
53 146
42 68
16 145
6 76
42 66
68 106
64 134
8 123
110 119
89 124
10 26
100 144
60 80
69 74
52 100
93 118
7 73
11 98
44 148
33 129
140 145
53 115
23 52
23 141
6 48
6 150
3 58
43 97
35 132
38 89...

output:

10
22
14
110
149
113
136
103
148
44
139

result:

ok OK

Test #19:

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

input:

92 4162 52
2 17
55 84
28 64
16 24
32 71
11 18
56 69
78 88
24 30
15 80
12 28
24 26
5 72
61 81
21 52
30 36
35 55
7 72
35 57
65 73
14 21
6 54
6 9
30 90
51 69
29 76
38 63
51 65
20 82
49 79
61 88
79 82
35 66
51 88
21 36
42 51
33 49
1 9
58 67
43 53
22 83
3 9
5 19
23 42
48 74
39 61
16 70
10 33
49 73
57 84
...

output:

10
28
12
76
29
67
58
89
50
13
64

result:

ok OK

Test #20:

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

input:

138 8440 10
48 76
49 78
21 97
106 123
55 80
54 127
27 42
50 107
13 27
9 28
61 114
98 131
3 107
57 109
113 135
65 119
13 56
14 32
40 47
75 100
72 123
31 63
46 130
118 119
57 74
52 95
110 132
51 135
43 82
28 48
34 63
11 97
15 47
60 78
25 30
75 111
31 87
61 73
17 51
2 22
25 117
10 95
5 50
66 138
18 100...

output:

22
48
28
9
90
116
132
117
137
130
121
115
120
88
125
66
52
124
35
72
123
106
76

result:

ok OK

Test #21:

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

input:

107 3805 22
87 106
25 94
71 73
20 54
50 85
25 80
7 14
25 37
11 65
50 88
89 98
30 68
39 63
34 100
58 92
1 37
29 103
34 90
3 32
65 80
14 69
17 101
11 13
76 104
16 39
31 41
39 70
71 86
15 25
82 95
19 58
46 55
56 57
54 78
22 50
6 42
2 58
19 78
9 46
38 88
45 93
74 86
19 101
12 74
36 60
60 97
62 82
46 59
...

output:

21
87
4
19
78
95
81
104
82
84
79
75
105
67
57
56
40
46
9
68
30
106

result:

ok OK

Test #22:

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

input:

98 4558 31
6 89
28 86
29 97
6 30
5 96
8 87
15 51
38 73
31 35
15 50
15 49
39 70
25 40
20 91
20 56
37 42
22 52
5 20
2 59
2 56
13 50
12 61
45 49
1 87
22 65
27 96
7 24
5 48
1 6
16 95
48 73
53 73
20 62
10 82
79 92
49 58
17 24
79 82
60 80
89 95
9 31
34 95
1 5
36 41
2 39
55 74
17 94
18 46
17 27
29 40
67 82...

output:

7
28
77
23
92
66
93
86

result:

ok OK

Test #23:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

141 8460 2
35 140
59 115
100 128
22 128
49 120
36 37
60 124
84 102
3 83
26 131
38 129
27 61
1 62
28 73
9 66
8 60
102 106
4 101
44 104
51 77
8 98
23 96
74 92
22 137
113 134
25 138
67 133
35 122
2 121
8 109
36 42
110 118
78 114
88 110
73 76
102 125
26 36
54 141
127 134
50 53
73 77
74 103
66 139
61 89
...

output:

11
35
122
87
135
141
54
49
120
20
37
140

result:

ok OK

Test #24:

score: 0
Accepted
time: 8ms
memory: 3840kb

input:

149 7462 69
4 38
29 40
112 137
20 115
38 135
65 81
55 137
4 70
29 87
9 16
44 95
25 120
15 34
121 136
69 104
14 35
2 76
51 78
9 145
3 55
106 136
91 115
11 102
9 119
86 126
38 119
7 119
96 110
30 135
113 132
49 65
8 118
2 25
47 83
9 91
93 101
107 139
96 137
62 119
3 44
39 146
104 110
37 89
101 133
68 ...

output:

14
121
77
68
97
100
109
103
144
114
128
127
130
106
136

result:

ok OK

Test #25:

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

input:

148 10057 54
17 48
83 85
2 47
139 147
74 77
77 79
35 78
64 77
39 62
23 96
23 40
85 103
18 142
17 63
52 127
7 93
80 101
73 117
30 138
37 122
97 106
43 119
18 48
70 105
34 106
40 57
72 92
48 136
95 100
33 34
37 106
68 80
116 122
21 105
45 69
45 141
43 72
18 47
73 141
44 86
50 65
1 141
31 94
6 8
2 145
...

output:

18
139
52
127
38
121
11
120
41
148
111
134
133
130
126
137
91
88
147

result:

ok OK

Test #26:

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

input:

136 8924 10
40 127
57 132
1 106
81 132
80 107
106 132
35 74
111 122
18 102
88 123
5 10
23 96
65 90
10 112
81 82
32 74
41 89
105 116
4 11
89 127
99 100
35 49
51 79
56 108
51 60
81 134
10 101
103 130
22 105
65 113
4 33
61 69
7 27
21 112
46 74
9 100
110 111
100 120
42 75
33 66
98 104
45 121
2 17
33 82
...

output:

12
40
66
33
82
98
87
104
128
125
41
89
127

result:

ok OK

Test #27:

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

input:

134 7947 27
24 32
14 132
3 85
18 76
10 82
3 98
34 125
37 88
8 132
23 118
1 57
7 31
6 32
21 58
65 104
117 131
114 118
52 117
70 83
46 55
47 85
15 24
47 60
28 62
51 88
90 98
1 98
40 68
9 69
37 111
28 132
61 72
54 110
21 22
13 39
6 124
55 105
61 125
14 102
96 127
36 58
73 125
64 110
20 130
70 123
61 62...

output:

19
24
15
33
56
108
111
115
112
130
119
134
110
109
126
100
81
124
6
32

result:

ok OK

Test #28:

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

input:

10 12 5
1 2
3 4
5 6
7 8
9 10
2 3
2 4
1 5
5 8
6 7
4 9
6 10

output:

8
1
5
6
10
9
4
3
2

result:

ok OK

Test #29:

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

input:

10 13 5
1 2
3 4
5 6
7 8
9 10
2 3
2 4
1 5
6 7
6 8
8 9
5 10
3 10

output:

10
1
5
6
7
8
9
10
3
4
2

result:

ok OK

Test #30:

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

input:

6 7 3
1 2
3 4
5 6
2 3
3 6
4 5
1 3

output:

4
3
6
5
4

result:

ok OK

Test #31:

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

input:

4 4 2
3 4
1 3
2 4
1 4

output:

3
3
1
4

result:

ok OK

Test #32:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

8 12 4
1 2
3 4
5 6
7 8
2 4
2 6
4 6
1 7
2 3
4 5
6 7
1 8

output:

8
1
8
7
6
5
4
3
2

result:

ok OK

Test #33:

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

input:

6 8 3
1 2
1 6
3 6
1 5
3 5
2 4
4 6
4 5

output:

6
1
6
3
5
4
2

result:

ok OK

Test #34:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

10 22 3
4 5
4 7
7 9
3 7
2 5
2 7
5 8
1 9
3 6
3 10
5 9
6 9
1 4
1 3
3 4
4 6
4 8
8 9
9 10
5 6
6 8
1 5

output:

8
4
7
9
1
3
6
8
5

result:

ok OK

Test #35:

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

input:

4 4 2
1 4
3 4
1 3
2 4

output:

3
1
3
4

result:

ok OK

Test #36:

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

input:

101 132 34
28 60
42 56
76 86
67 71
30 41
45 50
35 96
31 48
48 83
62 70
47 82
50 98
5 40
16 54
1 17
31 88
52 80
33 36
75 86
55 83
5 15
21 100
14 31
53 82
93 101
9 71
63 92
82 93
27 39
20 100
46 66
35 82
48 86
14 98
6 85
77 92
8 38
60 84
26 79
55 67
47 55
55 89
86 93
1 64
17 18
33 85
14 46
9 69
5 78
9...

output:

4
67
97
9
71

result:

ok OK

Test #37:

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

input:

18 26 9
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
1 17
2 16
3 15
4 14
5 13
6 12
7 11
8 10
2 3
4 5
6 7
8 9
10 11
12 13
14 15
16 17
1 18

output:

18
1
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2

result:

ok OK

Test #38:

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

input:

150 224 75
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
43 44
45 46
47 48
49 50
51 52
53 54
55 56
57 58
59 60
61 62
63 64
65 66
67 68
69 70
71 72
73 74
75 76
77 78
79 80
81 82
83 84
85 86
87 88
89 90
91 92
93 94
95 96
97 98
99 1...

output:

150
1
150
149
148
147
146
145
144
143
142
141
140
139
138
137
136
135
134
133
132
131
130
129
128
127
126
125
124
123
122
121
120
119
118
117
116
115
114
113
112
111
110
109
108
107
106
105
104
103
102
101
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
...

result:

ok OK

Test #39:

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

input:

150 224 75
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
43 44
45 46
47 48
49 50
51 52
53 54
55 56
57 58
59 60
61 62
63 64
65 66
67 68
69 70
71 72
73 74
75 76
77 78
79 80
81 82
83 84
85 86
87 88
89 90
91 92
93 94
95 96
97 98
99 1...

output:

150
1
150
149
148
147
146
145
144
143
142
141
140
139
138
137
136
135
134
133
132
131
130
129
128
127
126
125
124
123
122
121
120
119
118
117
116
115
114
113
112
111
110
109
108
107
106
105
104
103
102
101
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
...

result:

ok OK

Test #40:

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

input:

150 223 75
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
43 44
45 46
47 48
49 50
51 52
53 54
55 56
57 58
59 60
61 62
63 64
65 66
67 68
69 70
71 72
73 74
75 76
77 78
79 80
81 82
83 84
85 86
87 88
89 90
91 92
93 94
95 96
97 98
99 1...

output:

-1

result:

ok OK: both impossible

Test #41:

score: 0
Accepted
time: 5ms
memory: 4188kb

input:

150 10933 3
94 134
61 132
60 136
5 69
85 132
14 138
8 16
35 113
53 136
75 115
7 63
14 139
39 54
47 92
45 123
74 139
44 140
39 85
44 100
3 148
33 37
35 137
16 68
113 120
18 129
19 145
22 147
72 135
21 98
37 98
87 141
15 43
93 116
39 52
9 104
33 83
58 150
72 83
73 120
10 68
2 117
133 142
107 122
51 97...

output:

9
94
100
111
126
130
147
15
43
134

result:

ok OK