QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#180206 | #7250. Korn | xaphoenix# | TL | 1077ms | 103868kb | C++14 | 2.9kb | 2023-09-15 16:45:04 | 2023-09-15 16:45:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define LC k<<1
#define RC k<<1|1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repn(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = (n) - 1; i >= a; i--)
#define pern(i, a, n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef pair<ull, ull> PUU;
typedef pair<LL, LL> PLL;
const int N = 1100000;
const int M = 4100000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = 1e18;
const double eps = 1e-9;
mt19937_64 Rand((unsigned long long)new char);
#define rand Rand
int f[N], num;
int find(int x) {
return f[x] == x ? x : find(f[x]);
}
int tail, sz[N], sz2[N];
PII st[N];
void merge(int x, int y) {
int fx = find(x), fy = find(y);
st[++tail] = mp(fx, fy);
if (fx != fy) {
f[fx] = fy, sz[fy] += sz[fx], sz2[fy] += sz2[fx] + 1;
if (sz2[fy] == sz[fy]) num++;
}
else {
sz2[fx]++;
if (sz2[fx] == sz[fx]) num++;
}
}
vector<PII> e[M];
void insert(int k, int l, int r, int a, int b, PII c) {
if (l == a && r == b) {
e[k].pb(c);
return;
}
int mid = (l + r) / 2;
if (b <= mid) insert(LC, l, mid, a, b, c);
else if (a > mid) insert(RC, mid + 1, r, a, b, c);
else insert(LC, l, mid, a, mid, c), insert(RC, mid + 1, r, mid + 1, b, c);
}
int n, m, du[N];
vector<int> ans;
void work(int k, int l, int r) {
int cur = tail;
for (auto p: e[k]) {
int x = p.fi, y = p.se;
merge(x, y);
}
if (l == r) {
if (num == 0) ans.pb(l);
}
else {
int mid = (l + r) / 2;
work(LC, l, mid);
work(RC, mid + 1, r);
}
while (tail > cur) {
auto p = st[tail--];
int x = p.fi, y = p.se;
if (x == y) {
if (sz2[x] == sz[x]) num--;
sz2[x]--;
}
else {
if (sz2[y] == sz[y]) num--;
sz2[y] -= sz2[x] + 1;
sz[y] -= sz[x];
f[x] = x;
}
}
}
int main() {
IO;
cin >> n >> m;
repn(i, 1, n) f[i] = i, sz[i] = 1;
while (m--) {
int x, y;
cin >> x >> y;
du[x]++, du[y]++;
merge(x, y);
if (x > y) swap(x, y);
if (x > 1) insert(1, 1, n, 1, x - 1, mp(x, y));
if (x + 1 < y) insert(1, 1, n, x + 1, y - 1, mp(x, y));
if (y < n) insert(1, 1, n, y + 1, n, mp(x, y));
}
int flag = 0;
repn(i, 1, n) if (find(1) != find(i) || du[i] % 2 == 1) flag = 1;
if (flag) {
cout << "0\n";
return 0;
}
repn(i, 1, n) f[i] = i, sz[i] = 1, sz2[i] = 0;
tail = num = 0;
work(1, 1, n);
cout << ans.size() << "\n";
for (auto x: ans) cout << x << " ";
cout << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 99496kb
input:
6 8 3 5 5 1 3 4 4 1 6 3 1 6 2 3 1 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 21ms
memory: 99688kb
input:
3 3 1 2 2 3 3 1
output:
3 1 2 3
result:
ok 4 number(s): "3 1 2 3"
Test #3:
score: 0
Accepted
time: 15ms
memory: 99556kb
input:
3 2 1 3 2 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 10ms
memory: 99556kb
input:
5 7 1 3 4 2 1 2 1 4 5 2 1 5 3 2
output:
2 1 2
result:
ok 3 number(s): "2 1 2"
Test #5:
score: 0
Accepted
time: 16ms
memory: 99552kb
input:
5 5 5 3 1 5 2 1 4 2 3 4
output:
5 1 2 3 4 5
result:
ok 6 numbers
Test #6:
score: 0
Accepted
time: 15ms
memory: 99500kb
input:
5 6 4 1 5 3 1 5 4 3 3 2 1 2
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 8ms
memory: 99560kb
input:
10 14 2 3 5 2 4 3 6 3 10 3 7 8 5 6 7 5 9 10 8 4 9 7 5 1 7 3 1 3
output:
1 3
result:
ok 2 number(s): "1 3"
Test #8:
score: 0
Accepted
time: 21ms
memory: 99568kb
input:
10 10 4 5 2 9 8 1 7 10 6 8 1 10 2 7 3 6 3 4 5 9
output:
10 1 2 3 4 5 6 7 8 9 10
result:
ok 11 numbers
Test #9:
score: 0
Accepted
time: 12ms
memory: 99672kb
input:
10 16 1 6 9 8 9 3 5 1 1 2 4 1 2 9 7 9 9 4 1 8 9 5 1 3 9 6 10 9 1 10 1 7
output:
2 1 9
result:
ok 3 number(s): "2 1 9"
Test #10:
score: 0
Accepted
time: 15ms
memory: 99592kb
input:
100 168 53 8 35 44 98 64 28 85 35 62 95 11 41 62 46 12 73 62 28 49 31 66 84 61 38 70 60 13 69 67 44 62 35 77 9 36 39 62 52 27 50 87 38 24 4 62 16 88 94 37 46 62 100 90 98 4 19 78 52 55 54 91 32 62 52 51 5 14 80 41 24 62 20 15 11 1 22 62 69 62 72 62 29 62 38 62 90 62 56 30 58 18 40 62 89 38 12 62 70 ...
output:
1 62
result:
ok 2 number(s): "1 62"
Test #11:
score: 0
Accepted
time: 12ms
memory: 99688kb
input:
100 100 53 69 80 33 31 19 61 45 23 37 36 17 32 11 10 71 45 85 49 34 71 29 60 67 22 83 64 99 10 69 28 38 96 2 98 20 75 5 46 26 43 2 61 49 76 43 58 18 100 75 31 46 37 77 90 33 91 67 40 15 15 88 72 32 16 50 8 40 97 42 30 77 3 73 55 4 14 44 17 25 25 27 81 51 29 23 74 55 47 97 84 13 63 99 22 48 53 19 87 ...
output:
100 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 100
result:
ok 101 numbers
Test #12:
score: 0
Accepted
time: 21ms
memory: 99588kb
input:
100 196 44 85 68 86 86 55 44 56 86 76 16 86 86 74 18 44 86 29 4 86 44 21 86 91 75 86 44 26 86 85 86 81 44 52 31 44 86 7 58 86 48 44 44 79 86 93 86 57 15 44 44 100 86 3 95 44 44 93 44 46 44 39 30 44 86 32 89 86 47 44 53 86 44 41 44 24 77 44 62 44 44 13 37 86 86 88 86 20 2 86 44 1 43 86 53 44 44 71 62...
output:
2 44 86
result:
ok 3 number(s): "2 44 86"
Test #13:
score: 0
Accepted
time: 20ms
memory: 99952kb
input:
1000 1636 85 954 434 807 657 942 363 998 200 942 570 258 147 942 231 455 655 942 730 784 257 942 514 590 62 674 197 975 553 831 186 410 454 435 62 966 292 798 83 440 114 942 2 287 230 209 770 220 64 206 536 366 670 942 354 425 151 942 173 942 179 529 8 942 56 324 931 904 898 444 650 493 567 669 797 ...
output:
1 942
result:
ok 2 number(s): "1 942"
Test #14:
score: 0
Accepted
time: 17ms
memory: 99872kb
input:
1000 1000 154 824 455 878 521 429 806 795 887 180 629 775 934 605 796 129 364 826 314 612 282 675 612 799 417 575 111 515 194 220 4 667 271 377 797 583 265 5 911 213 636 407 452 924 588 251 906 770 707 598 305 239 825 860 716 110 112 865 447 703 6 403 126 856 830 970 789 270 394 528 380 462 130 923 ...
output:
1000 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 100 101...
result:
ok 1001 numbers
Test #15:
score: 0
Accepted
time: 31ms
memory: 99900kb
input:
1000 1996 346 472 472 632 472 737 666 742 666 139 666 246 666 545 666 765 178 666 958 666 864 472 136 666 242 472 666 142 472 731 472 146 472 844 472 140 265 666 472 460 666 78 563 666 666 129 244 472 908 666 666 260 832 472 472 823 866 666 666 655 728 472 538 666 666 420 87 666 303 666 34 472 829 6...
output:
2 472 666
result:
ok 3 number(s): "2 472 666"
Test #16:
score: 0
Accepted
time: 1077ms
memory: 103868kb
input:
10000 16544 8723 5854 6694 5854 5813 9842 7775 450 5552 5854 2938 5854 4135 4252 195 5854 8773 3397 217 5854 6649 5854 5200 9200 4801 5854 7952 2026 7657 5854 1411 4257 4380 5854 307 5854 5880 8432 6556 5854 7178 4059 4188 3428 6602 5854 134 5854 1758 8587 2157 7784 1638 447 8039 1320 3848 5854 3185...
output:
1 5854
result:
ok 2 number(s): "1 5854"
Test #17:
score: 0
Accepted
time: 28ms
memory: 102924kb
input:
10000 10000 6328 1933 3215 2119 133 597 5752 355 7264 8992 2759 8885 2141 1152 6369 553 8203 8771 9882 167 7977 1019 4924 3325 7006 2380 1669 8531 6813 3761 1904 7305 6037 5861 3036 8667 5650 9875 3979 4831 2967 4692 4652 5083 129 6518 635 1570 7543 4380 97 3534 5265 4098 9975 5326 1396 7440 3146 35...
output:
10000 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 100 10...
result:
ok 10001 numbers
Test #18:
score: -100
Time Limit Exceeded
input:
10000 19996 3251 3276 7746 2914 7968 3276 4133 3276 3276 8022 3276 7173 7524 3276 7746 4923 4310 7746 772 3276 7746 1759 7443 3276 8986 3276 7721 3276 2981 3276 7315 3276 3276 3539 2239 7746 3276 7321 3752 3276 8803 7746 3276 162 3276 5931 7746 1634 3276 7340 7746 6727 7746 5527 3825 7746 3276 309 3...