QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85255 | #5670. Group Guests | LJC00118 | AC ✓ | 917ms | 515160kb | C++14 | 6.9kb | 2023-03-07 14:24:13 | 2023-03-07 14:48:57 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
}
template <typename T>
void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
print(x); putchar(t);
}
const int N = 4e6 + 5;
vector <int> adj[N], tr[N], edg[N];
int fa[N], vis[N], s[N], seq[N], dep[N], ou[N], ov[N], deg[N], viscyc[N];
int n, m, len, ans1, ans2, olen;
void dfs1(int u) {
vis[u] = 1; seq[++len] = u;
for (auto v : adj[u]) {
if (!vis[v]) {
fa[v] = u; dep[v] = dep[u] + 1;
dfs1(v);
}
}
}
int par[N][21];
int up[N], tofa[N], siz[N];
void dfs2(int u) {
par[u][0] = fa[u];
for (int i = 1; i <= 20; i++) par[u][i] = par[par[u][i - 1]][i - 1];
for (auto v : tr[u]) {
dfs2(v);
s[u] += s[v]; siz[u] += siz[v];
}
assert(s[u] >= 0);
}
int jump(int u, int k) {
assert(k >= 0);
for (int i = 0; i <= 20; i++) {
if ((k >> i) & 1) {
u = par[u][i];
}
}
assert(u);
return u;
}
int main() {
read(m); read(n);
// assert(m >= 2 && n >= 3 && n <= 2 * m && n <= 1000000 && m <= 2000000);
for (int i = 1; i <= m; i++) {
int u, v;
read(u); read(v);
adj[u].push_back(v);
adj[v].push_back(u);
assert(u != v);
assert(1 <= u && u <= n && 1 <= v && v <= n);
}
for (int _ = 1; _ <= n; _++) {
if (vis[_]) continue;
len = 0; dfs1(_); olen = 0;
for (int i = 1; i <= len; i++) {
int u = seq[i];
for (auto v : adj[u]) {
if (dep[u] > dep[v]) continue;
++siz[v];
if (fa[v] == u) {
tr[u].push_back(v);
// fprintf(stderr, "u = %d, v = %d\n", u, v);
continue;
}
++olen; ou[olen] = u; ov[olen] = v;
++s[v]; --s[u];
}
}
int all = olen + len - 1;
if (all % 2 == 0) continue;
dfs2(_);
for (int i = 1; i <= olen; i++) {
++up[ov[i]];
++tofa[jump(ov[i], dep[ov[i]] - dep[ou[i]] - 1)];
}
// check size = 3 cycle
int can = 0;
for (int i = 1; i <= olen; i++) {
++deg[ou[i]]; ++deg[ov[i]];
}
for (int i = 1; i <= olen; i++) {
if (deg[ou[i]] < deg[ov[i]] || (deg[ou[i]] == deg[ov[i]] && ou[i] < ov[i])) {
edg[ov[i]].push_back(ou[i]);
} else {
edg[ou[i]].push_back(ov[i]);
}
}
for (int i = 1; i <= len; i++) {
int u = seq[i];
for (auto v : edg[u]) viscyc[v] = 1;
for (auto v : edg[u]) for (auto vv : edg[v]) {
can |= viscyc[vv];
}
for (auto v : edg[u]) viscyc[v] = 0;
if (can) break;
}
if (can) continue;
for (int i = 1; i <= olen; i++) {
if (deg[ou[i]] < deg[ov[i]] || (deg[ou[i]] == deg[ov[i]] && ou[i] < ov[i])) {
edg[ou[i]].push_back(ov[i]);
} else {
edg[ov[i]].push_back(ou[i]);
}
}
for (int i = 1; i <= len; i++) {
int u = seq[i];
for (auto v : edg[u]) viscyc[v] = 1;
for (auto v : edg[u]) {
// fprintf(stderr, "v = %d, fa[v] = %d\n", v, fa[v]);
// fprintf(stderr, "u = %d, v = %d\n", u, v);
if (viscyc[fa[v]]) {
if (s[v] > 1) can = 1;
else {
// fprintf(stderr, "u = %d, v = %d, fa[v] = %d, dep[u] = %d, dep[v] = %d\n", u, v, fa[v], dep[u], dep[v]);
if (dep[u] > dep[v]) {
assert(siz[v] >= 3);
if ((siz[v] - 3) % 2 == 0) can = 1;
} else {
assert(siz[v] >= 2);
if ((siz[v] - 2) % 2 == 0) can = 1;
}
}
}
}
for (auto v : edg[u]) viscyc[v] = 0;
if (can) break;
}
if (can) continue;
for (int i = 1; i <= olen; i++) {
int u = ou[i], v = ov[i];
// fprintf(stderr, "u = %d, v = %d\n", u, v);
if (fa[fa[v]] == u) {
int bel[3] = {0, 1, 2}, big[3] = {0, 0, 0}, cnt = 0;
if (s[fa[v]] - (s[v] - tofa[v])) bel[1] = 0, ++cnt;
assert(s[fa[v]] - (s[v] - tofa[v]) >= 0);
if (s[v] - tofa[v] - 1) bel[2] = 0, ++cnt;
assert(s[v] - tofa[v] - 1 >= 0);
if (tofa[v]) bel[2] = 1, ++cnt;
assert(tofa[v] >= 0);
if (cnt >= 2) can = 1;
else {
assert(all - siz[fa[v]] >= 0);
big[bel[0]] += all - siz[fa[v]];
assert(siz[fa[v]] - siz[v] - 1 >= 0);
big[bel[1]] += siz[fa[v]] - siz[v] - 1;
assert(siz[v] - 2 >= 0);
big[bel[2]] += siz[v] - 2;
if (big[0] % 2 == 0 && big[1] % 2 == 0 && big[2] % 2 == 0) can = 1;
}
}
if (can) break;
}
// fprintf(stderr, "_ = %d, len = %d, olen = %d\n", _, len, olen);
if (can) continue;
for (int i = 1; i <= len; i++) {
int u = seq[i];
if (s[u] > 1) {
can = 1;
break;
}
if ((int)edg[u].size() > 1) {
can = 1;
break;
}
}
if (can) {
++ans2;
continue;
}
for (int i = 1; i <= len; i++) {
int u = seq[i], good = 0, good2 = 0;
for (auto v : tr[u]) {
if (!s[v] && (siz[v] - 1) % 2 == 0) ++good;
good2 += s[v];
}
if (fa[u]) good2 += s[u];
if (fa[u] && !s[u] && (all - siz[u]) % 2 == 0) ++good;
if (good >= 3 || good2 >= 3 || (good2 && good)) {
can = 1;
break;
}
}
if (can) {
++ans2;
continue;
}
++ans1;
}
print(ans1, ' '); print(ans2, '\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 71ms
memory: 284676kb
input:
2 4 1 2 3 4
output:
2 0
result:
ok single line: '2 0'
Test #2:
score: 0
Accepted
time: 51ms
memory: 284780kb
input:
2 3 1 2 3 1
output:
0 0
result:
ok single line: '0 0'
Test #3:
score: 0
Accepted
time: 52ms
memory: 284704kb
input:
5 5 1 2 2 3 2 4 5 2 5 4
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 344ms
memory: 413364kb
input:
999990 666660 1 2 1 5 1 7 1 8 1 9 1 10 2 4 2 6 2 9 2 10 3 4 4 8 5 8 6 7 6 10 11 13 11 15 11 20 12 17 12 19 13 16 13 19 14 16 14 19 15 17 15 18 16 17 16 19 17 18 17 20 21 26 21 27 21 29 22 26 22 27 22 29 23 26 23 30 24 26 24 28 25 27 25 30 26 27 26 29 28 29 31 33 31 40 32 35 33 35 33 37 33 38 33 39 3...
output:
383 523
result:
ok single line: '383 523'
Test #5:
score: 0
Accepted
time: 331ms
memory: 413168kb
input:
999990 666660 1 2 1 3 1 5 1 8 2 4 2 7 3 8 3 9 3 10 4 5 4 10 5 9 6 7 6 9 9 10 11 12 11 14 11 19 11 20 12 16 13 17 13 19 14 15 14 16 15 16 15 18 16 18 16 19 17 20 18 20 21 24 21 26 21 28 22 23 23 24 23 27 23 28 24 25 24 27 25 26 25 27 25 30 26 29 27 29 27 30 31 32 31 36 31 37 32 37 33 34 33 35 33 39 3...
output:
349 522
result:
ok single line: '349 522'
Test #6:
score: 0
Accepted
time: 64ms
memory: 284684kb
input:
4 4 1 2 2 4 2 3 3 4
output:
0 0
result:
ok single line: '0 0'
Test #7:
score: 0
Accepted
time: 335ms
memory: 409776kb
input:
999991 647053 1 2 1 4 1 7 1 8 1 10 2 4 2 9 3 8 3 9 3 11 4 6 6 10 7 9 7 11 8 9 9 10 10 11 12 13 12 15 12 21 13 16 13 19 13 22 14 17 14 19 14 20 15 19 15 22 16 20 17 18 17 19 18 20 19 22 20 21 23 25 23 27 23 28 23 30 24 25 24 31 24 32 25 30 25 31 26 32 26 33 27 30 28 32 29 31 29 32 29 33 30 31 34 37 3...
output:
375 322
result:
ok single line: '375 322'
Test #8:
score: 0
Accepted
time: 314ms
memory: 409760kb
input:
999991 647053 1 8 2 7 2 9 2 11 3 6 4 5 5 7 5 8 5 9 5 10 5 11 6 8 6 10 8 9 8 10 8 11 10 11 12 13 12 16 12 22 13 14 13 15 13 16 15 18 15 20 15 22 16 19 16 20 16 21 17 18 17 20 19 22 20 22 21 22 23 24 23 26 23 28 23 33 24 25 24 30 25 26 25 29 25 33 26 32 26 33 28 29 28 31 28 33 29 33 31 33 32 33 34 36 ...
output:
366 307
result:
ok single line: '366 307'
Test #9:
score: 0
Accepted
time: 47ms
memory: 284736kb
input:
5 5 1 2 2 4 2 3 5 4 3 4
output:
0 1
result:
ok single line: '0 1'
Test #10:
score: 0
Accepted
time: 362ms
memory: 418520kb
input:
999991 705876 1 5 1 9 2 5 2 7 2 8 3 4 5 6 6 7 6 9 6 10 6 11 6 12 7 9 7 11 8 10 9 10 11 12 13 14 13 15 13 16 13 18 13 19 14 17 15 19 15 21 16 21 17 19 18 24 19 20 20 21 21 22 21 23 22 23 23 24 25 28 25 31 25 34 26 31 27 28 27 32 28 29 28 33 28 36 29 32 29 33 29 36 30 35 31 34 31 35 32 34 32 35 37 45 ...
output:
1032 1376
result:
ok single line: '1032 1376'
Test #11:
score: 0
Accepted
time: 339ms
memory: 418564kb
input:
999991 705876 1 7 2 10 2 11 2 12 3 7 3 9 4 5 4 8 4 9 5 7 5 9 6 7 6 9 6 11 7 11 9 10 11 12 13 16 13 17 13 24 14 16 14 24 15 17 15 20 15 24 16 17 16 19 17 20 17 22 17 24 18 20 19 23 20 22 20 23 25 26 25 28 25 35 26 31 27 33 27 35 28 32 29 33 29 35 29 36 30 33 30 34 32 33 32 35 33 35 33 36 34 35 37 38 ...
output:
990 1439
result:
ok single line: '990 1439'
Test #12:
score: 0
Accepted
time: 67ms
memory: 284680kb
input:
6 6 1 4 3 2 4 3 4 6 4 5 4 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 53ms
memory: 284740kb
input:
7 7 1 6 6 7 6 2 2 5 2 3 2 4 3 4
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 64ms
memory: 284696kb
input:
8 8 1 2 2 7 2 8 7 8 5 2 2 3 2 4 5 6
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 56ms
memory: 284568kb
input:
12 8 1 2 1 3 2 3 3 4 3 5 4 5 6 5 6 7 5 7 2 7 7 8 2 8
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 43ms
memory: 284816kb
input:
5 4 1 2 1 3 2 3 2 4 3 4
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 67ms
memory: 284852kb
input:
6 7 1 2 2 7 2 3 3 4 4 5 5 6
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 52ms
memory: 284684kb
input:
7 8 1 4 4 5 6 7 6 8 2 4 2 3 6 3
output:
0 1
result:
ok single line: '0 1'
Test #19:
score: 0
Accepted
time: 52ms
memory: 284864kb
input:
7 8 1 2 1 3 1 4 5 6 5 7 5 8 1 5
output:
0 1
result:
ok single line: '0 1'
Test #20:
score: 0
Accepted
time: 70ms
memory: 284864kb
input:
4 4 1 3 1 4 2 4 2 3
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 52ms
memory: 284884kb
input:
5 5 1 2 1 5 2 4 4 3 3 5
output:
1 0
result:
ok single line: '1 0'
Test #22:
score: 0
Accepted
time: 56ms
memory: 284864kb
input:
9 12 1 2 1 3 4 5 5 6 7 9 8 9 10 11 10 12 11 12
output:
0 0
result:
ok single line: '0 0'
Test #23:
score: 0
Accepted
time: 72ms
memory: 284732kb
input:
186 228 1 2 1 3 5 6 5 8 9 11 9 12 13 14 13 15 13 16 17 18 18 19 21 23 22 23 25 26 25 27 26 27 29 32 30 31 33 34 33 36 34 35 37 39 37 40 38 39 41 42 41 43 41 44 42 43 45 46 46 48 49 51 50 52 53 54 53 55 54 56 57 60 58 60 61 62 61 64 62 64 65 67 65 68 66 68 69 70 69 71 69 72 70 72 74 75 74 76 77 78 78...
output:
18 4
result:
ok single line: '18 4'
Test #24:
score: 0
Accepted
time: 40ms
memory: 284668kb
input:
3 4 1 2 3 4 3 2
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: 0
Accepted
time: 57ms
memory: 285608kb
input:
5110 5065 1 2 1 3 6 7 6 9 11 13 11 14 16 17 16 18 16 19 21 22 21 25 26 28 26 30 31 32 31 33 31 35 36 39 36 40 41 42 41 44 41 45 46 48 46 49 46 50 51 52 51 53 51 54 51 55 56 57 57 58 61 63 62 63 66 67 66 68 67 68 71 74 72 73 76 77 76 79 77 78 81 83 81 84 82 83 86 87 86 88 86 89 87 88 91 95 92 93 96 9...
output:
142 140
result:
ok single line: '142 140'
Test #26:
score: 0
Accepted
time: 67ms
memory: 284864kb
input:
3 4 1 2 2 3 2 4
output:
0 1
result:
ok single line: '0 1'
Test #27:
score: 0
Accepted
time: 101ms
memory: 319648kb
input:
245745 196512 1 2 1 3 7 8 7 10 13 15 13 16 19 20 19 21 19 22 25 26 25 29 31 33 31 35 37 38 37 39 37 41 43 46 43 47 49 50 49 52 49 53 55 57 55 58 55 59 61 62 61 63 61 64 61 65 67 68 67 72 73 75 73 78 79 80 79 81 79 84 85 88 85 90 91 92 91 94 91 96 97 99 97 100 97 102 103 104 103 105 103 106 103 108 1...
output:
2097 2626
result:
ok single line: '2097 2626'
Test #28:
score: 0
Accepted
time: 81ms
memory: 284656kb
input:
5 6 1 6 2 6 3 6 4 6 5 6
output:
0 1
result:
ok single line: '0 1'
Test #29:
score: 0
Accepted
time: 266ms
memory: 430536kb
input:
999999 841330 1 2 1 3 8 9 8 11 15 17 15 18 22 23 22 24 22 25 29 30 29 33 36 38 36 40 43 44 43 45 43 47 50 53 50 54 57 58 57 60 57 61 64 66 64 67 64 68 71 72 71 73 71 74 71 75 78 79 78 83 85 87 85 90 92 93 92 94 92 97 99 102 99 104 106 107 106 109 106 111 113 115 113 116 113 118 120 121 120 122 120 1...
output:
7646 12754
result:
ok single line: '7646 12754'
Test #30:
score: 0
Accepted
time: 278ms
memory: 418740kb
input:
999992 755307 1 6 2 4 2 5 2 7 3 5 3 7 4 5 4 6 8 9 8 13 9 11 9 12 9 14 10 12 10 14 11 12 11 13 15 17 15 20 16 18 16 19 16 21 17 19 17 21 18 19 18 20 22 23 22 24 22 27 23 25 23 26 23 28 24 26 24 28 25 26 25 27 29 32 29 34 30 32 30 33 30 35 31 33 31 35 32 33 32 34 36 37 36 39 36 41 37 39 37 40 37 42 38...
output:
3532 7627
result:
ok single line: '3532 7627'
Test #31:
score: 0
Accepted
time: 285ms
memory: 416900kb
input:
999994 740684 1 3 1 4 1 5 2 5 2 6 3 4 3 5 3 6 3 7 4 6 4 7 8 9 8 10 8 11 8 12 9 12 9 13 10 11 10 12 10 13 10 14 11 13 11 14 15 20 16 19 16 20 17 18 17 19 17 20 17 21 18 20 18 21 22 23 22 27 23 26 23 27 24 25 24 26 24 27 24 28 25 27 25 28 29 31 29 34 30 33 30 34 31 32 31 33 31 34 31 35 32 34 32 35 36 ...
output:
3201 7345
result:
ok single line: '3201 7345'
Test #32:
score: 0
Accepted
time: 278ms
memory: 412492kb
input:
999992 706979 1 2 1 3 1 7 2 3 3 4 3 5 4 6 5 6 8 11 8 14 9 10 10 11 10 12 11 13 12 13 15 16 15 18 15 21 16 17 17 18 17 19 18 20 19 20 22 24 22 25 22 28 23 24 24 25 24 26 25 27 26 27 29 30 29 31 29 32 29 35 30 31 31 32 31 33 32 34 33 34 36 40 36 42 37 38 38 39 38 40 39 41 40 41 43 44 43 47 43 49 44 45...
output:
2402 4121
result:
ok single line: '2402 4121'
Test #33:
score: 0
Accepted
time: 292ms
memory: 402956kb
input:
999994 646072 1 5 1 7 2 3 2 4 2 6 3 6 4 5 4 7 5 6 8 9 8 12 8 14 9 10 9 11 9 13 10 13 11 12 11 14 12 13 15 17 15 19 15 21 16 17 16 18 16 20 17 20 18 19 18 21 19 20 22 23 22 24 22 26 22 28 23 24 23 25 23 27 24 27 25 26 25 28 26 27 29 32 29 33 29 35 30 31 30 32 30 34 31 34 32 33 32 35 33 34 36 37 36 39...
output:
943 2394
result:
ok single line: '943 2394'
Test #34:
score: 0
Accepted
time: 255ms
memory: 419548kb
input:
999995 753298 1 2 1 6 1 7 2 3 2 5 2 6 3 4 5 7 8 10 8 13 8 14 9 10 9 12 9 13 10 11 12 14 15 16 15 17 15 20 15 21 16 17 16 19 16 20 17 18 19 21 22 25 22 27 22 28 23 24 23 26 23 27 24 25 26 28 29 30 29 32 29 34 29 35 30 31 30 33 30 34 31 32 33 35 36 38 36 39 36 41 36 42 37 38 37 40 37 41 38 39 40 42 43...
output:
3698 7209
result:
ok single line: '3698 7209'
Test #35:
score: 0
Accepted
time: 316ms
memory: 409700kb
input:
999989 688429 1 2 1 3 1 4 1 5 2 3 2 4 2 5 2 6 2 7 3 4 3 6 4 5 4 6 5 7 8 13 9 10 9 11 9 12 9 13 9 14 10 11 10 13 11 12 11 13 12 14 15 16 15 20 16 17 16 18 16 19 16 20 16 21 17 18 17 20 18 19 18 20 19 21 22 24 22 27 23 24 23 25 23 26 23 27 23 28 24 25 24 27 25 26 25 27 26 28 29 30 29 31 29 34 30 31 30...
output:
1310 3756
result:
ok single line: '1310 3756'
Test #36:
score: 0
Accepted
time: 279ms
memory: 405828kb
input:
999993 666330 1 3 1 5 1 6 1 7 2 3 2 4 2 5 2 6 2 7 3 4 3 6 4 6 4 7 5 7 8 9 8 10 8 12 8 13 8 14 9 10 9 11 9 12 9 13 9 14 10 11 10 13 11 13 11 14 12 14 15 18 15 19 15 20 15 21 16 17 16 18 16 19 16 20 16 21 17 18 17 20 18 20 18 21 19 21 22 23 22 25 22 26 22 27 22 28 23 24 23 25 23 26 23 27 23 28 24 25 2...
output:
835 3556
result:
ok single line: '835 3556'
Test #37:
score: 0
Accepted
time: 314ms
memory: 402588kb
input:
999993 641725 1 6 2 3 2 4 2 5 2 6 3 6 4 5 5 6 5 7 8 9 8 13 9 10 9 11 9 12 9 13 10 13 11 12 12 13 12 14 15 17 15 20 16 17 16 18 16 19 16 20 17 20 18 19 19 20 19 21 22 23 22 24 22 27 23 24 23 25 23 26 23 27 24 27 25 26 26 27 26 28 29 32 29 34 30 31 30 32 30 33 30 34 31 34 32 33 33 34 33 35 36 37 36 39...
output:
331 2414
result:
ok single line: '331 2414'
Test #38:
score: 0
Accepted
time: 257ms
memory: 400940kb
input:
999994 629048 1 2 1 3 1 5 1 7 2 3 2 4 2 5 3 4 4 7 5 6 5 7 8 11 8 12 8 14 9 10 9 11 9 12 10 11 11 14 12 13 12 14 15 16 15 18 15 19 15 21 16 17 16 18 16 19 17 18 18 21 19 20 19 21 22 24 22 25 22 26 22 28 23 24 23 25 23 26 24 25 25 28 26 27 26 28 29 30 29 31 29 32 29 33 29 35 30 31 30 32 30 33 31 32 32...
output:
164 2050
result:
ok single line: '164 2050'
Test #39:
score: 0
Accepted
time: 294ms
memory: 407488kb
input:
999999 680225 1 2 1 3 1 6 1 7 2 3 2 4 3 4 3 6 3 7 4 6 4 7 5 6 5 7 8 11 8 13 8 14 9 10 9 11 10 11 10 13 10 14 11 13 11 14 12 13 12 14 15 16 15 18 15 20 15 21 16 17 16 18 17 18 17 20 17 21 18 20 18 21 19 20 19 21 22 24 22 25 22 27 22 28 23 24 23 25 24 25 24 27 24 28 25 27 25 28 26 27 26 28 29 30 29 31...
output:
3578 4667
result:
ok single line: '3578 4667'
Test #40:
score: 0
Accepted
time: 282ms
memory: 413456kb
input:
999994 710822 1 2 1 3 1 5 2 4 2 7 3 6 3 7 4 5 6 7 8 11 8 12 9 11 9 14 10 13 10 14 11 12 13 14 15 16 15 18 15 19 16 18 16 21 17 20 17 21 18 19 20 21 22 24 22 25 22 26 23 25 23 28 24 27 24 28 25 26 27 28 29 30 29 31 29 32 29 33 30 32 30 35 31 34 31 35 32 33 34 35 36 41 37 39 37 42 38 41 38 42 39 40 41...
output:
1590 5625
result:
ok single line: '1590 5625'
Test #41:
score: 0
Accepted
time: 258ms
memory: 404540kb
input:
999999 654864 1 2 1 4 1 6 1 7 2 5 3 5 3 6 3 7 4 7 6 7 8 10 8 11 8 13 8 14 9 12 10 12 10 13 10 14 11 14 13 14 15 16 15 17 15 18 15 20 15 21 16 19 17 19 17 20 17 21 18 21 20 21 22 26 22 27 22 28 23 26 24 26 24 27 24 28 25 28 27 28 29 30 29 33 29 34 29 35 30 33 31 33 31 34 31 35 32 35 34 35 36 38 36 40...
output:
653 1686
result:
ok single line: '653 1686'
Test #42:
score: 0
Accepted
time: 271ms
memory: 409364kb
input:
999994 683298 1 2 1 4 1 7 2 4 2 6 2 7 3 4 3 5 3 7 4 5 4 6 4 7 6 7 8 10 8 11 8 14 9 11 9 13 9 14 10 11 10 12 10 14 11 12 11 13 11 14 13 14 15 16 15 17 15 18 15 21 16 18 16 20 16 21 17 18 17 19 17 21 18 19 18 20 18 21 20 21 22 26 22 28 23 25 23 27 23 28 24 25 24 26 24 28 25 26 25 27 25 28 27 28 29 30 ...
output:
944 4865
result:
ok single line: '944 4865'
Test #43:
score: 0
Accepted
time: 299ms
memory: 402244kb
input:
999994 634011 1 2 1 3 1 6 1 7 2 3 2 4 2 5 2 6 3 4 3 5 3 7 4 6 5 6 6 7 8 11 8 13 8 14 9 10 9 11 9 12 9 13 10 11 10 12 10 14 11 13 12 13 13 14 15 16 15 18 15 20 15 21 16 17 16 18 16 19 16 20 17 18 17 19 17 21 18 20 19 20 20 21 22 24 22 25 22 27 22 28 23 24 23 25 23 26 23 27 24 25 24 26 24 28 25 27 26 ...
output:
256 2136
result:
ok single line: '256 2136'
Test #44:
score: 0
Accepted
time: 248ms
memory: 393912kb
input:
999999 586642 2 3 2 4 2 5 2 7 3 4 3 5 3 6 4 5 4 7 5 6 6 7 8 9 9 10 9 11 9 12 9 14 10 11 10 12 10 13 11 12 11 14 12 13 13 14 15 17 16 17 16 18 16 19 16 21 17 18 17 19 17 20 18 19 18 21 19 20 20 21 22 23 22 24 23 24 23 25 23 26 23 28 24 25 24 26 24 27 25 26 25 28 26 27 27 28 29 32 30 31 30 32 30 33 30...
output:
223 715
result:
ok single line: '223 715'
Test #45:
score: 0
Accepted
time: 276ms
memory: 410776kb
input:
999990 686567 1 3 1 4 1 5 1 6 2 5 2 7 5 7 6 7 8 9 8 10 8 11 8 12 8 13 9 12 9 14 12 14 13 14 15 21 16 19 16 21 19 21 20 21 22 23 22 28 23 26 23 28 26 28 27 28 29 31 29 35 30 33 30 35 33 35 34 35 36 37 36 38 36 42 37 40 37 42 40 42 41 42 43 46 43 49 44 47 44 49 47 49 48 49 50 51 50 53 50 56 51 54 51 5...
output:
931 4522
result:
ok single line: '931 4522'
Test #46:
score: 0
Accepted
time: 308ms
memory: 401912kb
input:
999990 632338 1 2 1 3 1 4 1 5 1 6 1 7 2 7 4 5 4 6 5 7 6 7 9 10 9 14 11 12 11 13 12 14 13 14 15 16 16 17 16 21 18 19 18 20 19 21 20 21 22 24 23 24 23 28 25 26 25 27 26 28 27 28 29 30 29 31 30 31 30 35 32 33 32 34 33 35 34 35 36 39 37 38 37 42 39 40 39 41 40 42 41 42 43 44 43 46 44 45 44 49 46 47 46 4...
output:
151 2420
result:
ok single line: '151 2420'
Test #47:
score: 0
Accepted
time: 297ms
memory: 395912kb
input:
999993 597905 1 2 1 4 1 5 1 6 2 5 2 7 3 6 3 7 4 5 4 7 5 7 6 7 8 10 8 11 8 12 8 13 9 12 9 14 10 13 10 14 11 12 11 14 12 14 13 14 15 16 15 17 15 18 15 19 15 20 16 19 16 21 17 20 17 21 18 19 18 21 19 21 20 21 22 28 23 26 23 28 24 27 24 28 25 26 25 28 26 28 27 28 29 30 29 35 30 33 30 35 31 34 31 35 32 3...
output:
396 361
result:
ok single line: '396 361'
Test #48:
score: 0
Accepted
time: 292ms
memory: 398032kb
input:
999996 615720 1 4 2 3 2 4 2 6 3 5 3 6 5 6 5 7 6 7 8 9 8 11 9 10 9 11 9 13 10 12 10 13 12 13 12 14 13 14 15 17 15 18 16 17 16 18 16 20 17 19 17 20 19 20 19 21 20 21 22 23 22 24 22 25 23 24 23 25 23 27 24 26 24 27 26 27 26 28 27 28 29 33 30 31 30 32 30 34 31 33 31 34 33 34 33 35 34 35 36 37 36 40 37 3...
output:
277 414
result:
ok single line: '277 414'
Test #49:
score: 0
Accepted
time: 270ms
memory: 393360kb
input:
999990 581357 1 4 1 5 1 6 2 3 2 6 3 4 4 5 4 6 5 6 5 7 6 7 8 9 8 11 8 12 8 13 9 10 9 13 10 11 11 12 11 13 12 13 12 14 13 14 15 17 15 18 15 19 15 20 16 17 16 20 17 18 18 19 18 20 19 20 19 21 20 21 22 23 22 24 22 25 22 26 22 27 23 24 23 27 24 25 25 26 25 27 26 27 26 28 27 28 29 35 30 31 30 34 31 32 32 ...
output:
104 179
result:
ok single line: '104 179'
Test #50:
score: 0
Accepted
time: 250ms
memory: 385572kb
input:
999987 538132 1 2 1 3 1 4 2 3 2 4 2 6 2 7 3 4 3 7 4 5 4 7 5 6 5 7 6 7 8 12 9 10 9 11 9 13 9 14 10 11 10 14 11 12 11 14 12 13 12 14 13 14 15 16 15 19 16 17 16 18 16 20 16 21 17 18 17 21 18 19 18 21 19 20 19 21 20 21 22 24 22 26 23 24 23 25 23 27 23 28 24 25 24 28 25 26 25 28 26 27 26 28 27 28 29 30 2...
output:
102 6
result:
ok single line: '102 6'
Test #51:
score: 0
Accepted
time: 86ms
memory: 286392kb
input:
20215 8827 1 2 1 3 1 6 2 5 2 6 3 4 3 5 3 6 3 7 4 5 4 6 4 7 5 6 5 7 6 7 8 11 8 13 9 12 9 13 10 11 10 12 10 13 10 14 11 12 11 13 11 14 12 13 12 14 13 14 15 16 15 18 15 20 16 19 16 20 17 18 17 19 17 20 17 21 18 19 18 20 18 21 19 20 19 21 20 21 22 24 22 25 22 27 23 26 23 27 24 25 24 26 24 27 24 28 25 26...
output:
0 0
result:
ok single line: '0 0'
Test #52:
score: 0
Accepted
time: 71ms
memory: 284824kb
input:
4 5 1 2 2 3 3 4 4 5
output:
0 0
result:
ok single line: '0 0'
Test #53:
score: 0
Accepted
time: 249ms
memory: 397500kb
input:
999996 614440 1 2 1 3 1 4 1 5 1 7 1 8 2 3 2 4 2 6 2 7 3 6 3 7 4 5 4 6 4 8 5 7 9 14 9 15 9 16 10 11 10 12 10 14 10 15 11 14 11 15 12 13 12 14 12 16 13 15 17 18 17 22 17 23 17 24 18 19 18 20 18 22 18 23 19 22 19 23 20 21 20 22 20 24 21 23 25 27 25 30 25 31 25 32 26 27 26 28 26 30 26 31 27 30 27 31 28 ...
output:
38 1247
result:
ok single line: '38 1247'
Test #54:
score: 0
Accepted
time: 244ms
memory: 380896kb
input:
1000000 513824 1 4 2 5 2 8 3 6 4 5 4 6 4 7 4 8 5 6 6 7 6 8 9 10 9 12 10 13 10 16 11 14 12 13 12 14 12 15 12 16 13 14 14 15 14 16 17 19 17 20 18 21 18 24 19 22 20 21 20 22 20 23 20 24 21 22 22 23 22 24 25 26 25 27 25 28 26 29 26 32 27 30 28 29 28 30 28 31 28 32 29 30 30 31 30 32 33 37 34 37 34 40 35 ...
output:
8 0
result:
ok single line: '8 0'
Test #55:
score: 0
Accepted
time: 253ms
memory: 377240kb
input:
999993 491984 1 3 1 7 2 4 2 5 2 6 3 5 3 8 4 6 4 7 5 6 5 7 5 8 6 7 6 8 9 10 9 11 9 15 10 12 10 13 10 14 11 13 11 16 12 14 12 15 13 14 13 15 13 16 14 15 14 16 17 20 17 23 18 20 18 21 18 22 19 21 19 24 20 22 20 23 21 22 21 23 21 24 22 23 22 24 25 26 25 28 25 31 26 28 26 29 26 30 27 29 27 32 28 30 28 31...
output:
7 0
result:
ok single line: '7 0'
Test #56:
score: 0
Accepted
time: 244ms
memory: 397052kb
input:
999993 602296 1 3 1 4 2 3 2 4 2 6 2 7 2 8 3 4 4 7 4 8 5 8 6 7 7 8 9 10 9 11 9 12 10 11 10 12 10 14 10 15 10 16 11 12 12 15 12 16 13 16 14 15 15 16 17 21 18 19 18 20 18 22 18 23 18 24 19 20 20 23 20 24 21 24 22 23 23 24 25 26 25 29 26 27 26 28 26 30 26 31 26 32 27 28 28 31 28 32 29 32 30 31 31 32 33 ...
output:
10 374
result:
ok single line: '10 374'
Test #57:
score: 0
Accepted
time: 239ms
memory: 398816kb
input:
999997 620840 1 2 1 3 1 4 1 5 1 7 2 3 2 4 2 5 2 6 2 7 2 8 3 4 3 6 4 6 4 8 5 6 5 8 9 14 9 15 10 11 10 12 10 13 10 14 10 15 10 16 11 12 11 14 12 14 12 16 13 14 13 16 17 18 17 22 17 23 18 19 18 20 18 21 18 22 18 23 18 24 19 20 19 22 20 22 20 24 21 22 21 24 25 27 25 30 25 31 26 27 26 28 26 29 26 30 26 3...
output:
656 1809
result:
ok single line: '656 1809'
Test #58:
score: 0
Accepted
time: 71ms
memory: 284628kb
input:
5 6 1 2 3 4 5 6 2 3 4 5
output:
1 0
result:
ok single line: '1 0'
Test #59:
score: 0
Accepted
time: 245ms
memory: 335372kb
input:
999992 642852 1 4 1 7 1 8 1 9 2 4 2 5 3 6 4 6 5 6 5 8 5 9 6 8 7 9 8 9 10 12 10 15 10 17 10 18 11 12 11 18 12 17 13 15 13 16 13 17 14 15 14 16 14 18 15 18 19 21 19 23 19 25 19 27 20 22 20 24 20 25 20 27 21 23 21 24 22 25 23 24 23 25 23 26 28 31 28 33 29 32 29 34 29 35 29 36 30 33 31 32 31 33 31 35 32...
output:
123 0
result:
ok single line: '123 0'
Test #60:
score: 0
Accepted
time: 277ms
memory: 402200kb
input:
999990 599994 1 3 1 4 1 6 1 7 1 8 1 9 3 4 3 6 4 7 5 7 5 8 5 9 7 8 7 9 8 9 10 11 10 13 10 18 11 12 11 15 11 18 12 17 13 14 13 15 13 18 14 15 14 18 15 16 15 18 16 17 19 20 19 23 19 25 19 26 20 21 20 23 21 27 22 23 22 24 22 25 22 26 22 27 23 25 23 26 24 26 28 29 28 32 28 33 28 36 29 34 29 35 29 36 30 3...
output:
57 40
result:
ok single line: '57 40'
Test #61:
score: 0
Accepted
time: 46ms
memory: 284680kb
input:
8 9 9 8 6 7 3 2 5 4 1 2 4 3 6 5 7 8
output:
0 0
result:
ok single line: '0 0'
Test #62:
score: 0
Accepted
time: 917ms
memory: 436796kb
input:
999999 1000000 1 560136 2 102142 2 236736 3 309371 3 491463 4 538764 5 470246 6 278170 7 227277 8 673767 9 37182 9 231457 11 414293 11 583390 11 812999 11 868721 11 925233 12 254802 12 517049 12 530488 12 910757 12 943612 13 901211 14 1496 14 802703 15 684146 18 159626 18 209532 18 394262 18 583396 ...
output:
20012 719
result:
ok single line: '20012 719'
Test #63:
score: 0
Accepted
time: 142ms
memory: 309812kb
input:
998991 1414 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1...
output:
0 0
result:
ok single line: '0 0'
Test #64:
score: 0
Accepted
time: 384ms
memory: 515160kb
input:
999999 999999 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
1 0
result:
ok single line: '1 0'
Test #65:
score: 0
Accepted
time: 350ms
memory: 463512kb
input:
999997 749999 1 2 2 3 3 1 2 4 4 5 5 6 6 4 5 7 7 8 8 9 9 7 8 10 10 11 11 12 12 10 11 13 13 14 14 15 15 13 14 16 16 17 17 18 18 16 17 19 19 20 20 21 21 19 20 22 22 23 23 24 24 22 23 25 25 26 26 27 27 25 26 28 28 29 29 30 30 28 29 31 31 32 32 33 33 31 32 34 34 35 35 36 36 34 35 37 37 38 38 39 39 37 38 ...
output:
0 1
result:
ok single line: '0 1'
Test #66:
score: 0
Accepted
time: 418ms
memory: 463388kb
input:
999999 750001 1 2 2 3 3 1 2 4 4 5 5 6 6 4 5 7 7 8 8 9 9 7 8 10 10 11 11 12 12 10 11 13 13 14 14 15 15 13 14 16 16 17 17 18 18 16 17 19 19 20 20 21 21 19 20 22 22 23 23 24 24 22 23 25 25 26 26 27 27 25 26 28 28 29 29 30 30 28 29 31 31 32 32 33 33 31 32 34 34 35 35 36 36 34 35 37 37 38 38 39 39 37 38 ...
output:
0 0
result:
ok single line: '0 0'
Test #67:
score: 0
Accepted
time: 487ms
memory: 491704kb
input:
999997 999998 1 2 1 3 1 4 3 6 5 6 5 7 5 8 7 10 9 10 9 11 9 12 11 14 13 14 13 15 13 16 15 18 17 18 17 19 17 20 19 22 21 22 21 23 21 24 23 26 25 26 25 27 25 28 27 30 29 30 29 31 29 32 31 34 33 34 33 35 33 36 35 38 37 38 37 39 37 40 39 42 41 42 41 43 41 44 43 46 45 46 45 47 45 48 47 50 49 50 49 51 49 5...
output:
1 0
result:
ok single line: '1 0'
Test #68:
score: 0
Accepted
time: 352ms
memory: 440664kb
input:
999915 952300 1 41 1 47 1 72 2 16 2 88 2 95 3 9 3 26 3 91 4 21 4 37 4 85 5 14 5 49 5 88 6 25 7 71 7 74 7 84 8 22 9 34 9 83 10 16 10 90 11 18 12 35 12 52 14 17 14 44 14 72 15 26 15 80 15 83 16 42 17 65 18 29 18 85 19 41 19 74 21 38 22 25 22 37 22 53 23 38 24 39 24 63 24 98 25 64 25 91 26 44 26 55 26 ...
output:
15511 1803
result:
ok single line: '15511 1803'
Test #69:
score: 0
Accepted
time: 341ms
memory: 442360kb
input:
999975 995000 1 359 1 729 1 966 2 263 2 487 4 372 4 391 4 877 5 883 6 248 6 254 6 703 7 141 7 333 8 496 8 602 8 934 9 747 10 283 11 386 11 815 12 954 13 963 14 437 14 891 15 274 15 826 16 56 16 278 16 893 18 247 18 789 18 826 19 409 19 695 20 158 20 624 20 838 20 993 21 289 21 734 22 936 22 938 23 2...
output:
19402 813
result:
ok single line: '19402 813'
Test #70:
score: 0
Accepted
time: 443ms
memory: 438248kb
input:
990495 990000 1 4654 2 553 2 4245 3 2524 3 3264 3 4715 3 5674 3 8204 4 5011 5 2857 5 9071 6 1514 6 5066 6 6536 6 7994 7 827 7 6412 8 7290 9 871 9 1936 9 2124 9 6867 11 8860 12 1347 12 3879 12 8952 13 1635 13 3529 14 3313 14 7551 14 8286 15 307 15 614 15 6202 15 7888 15 7935 16 2070 17 689 18 2352 18...
output:
19786 687
result:
ok single line: '19786 687'
Test #71:
score: 0
Accepted
time: 335ms
memory: 440332kb
input:
999955 909050 1 4 1 13 1 28 1 33 1 36 2 25 3 42 4 16 5 25 7 22 7 24 7 30 7 33 7 40 7 50 8 19 8 27 9 17 9 24 10 19 10 20 10 24 10 37 12 34 13 32 13 36 14 36 15 24 16 20 16 31 17 22 18 24 19 32 19 37 19 43 20 27 20 44 21 27 21 33 24 31 24 36 24 41 25 26 26 44 27 28 27 39 27 40 28 36 28 49 30 37 30 39 ...
output:
11763 2903
result:
ok single line: '11763 2903'
Test #72:
score: 0
Accepted
time: 328ms
memory: 443848kb
input:
999900 990000 1 33 1 290 1 323 1 327 1 341 2 12 2 17 2 46 2 198 3 204 3 256 4 27 4 313 6 236 7 217 9 153 9 431 10 21 10 415 10 419 11 58 12 55 12 128 14 390 15 34 16 240 16 321 17 262 18 231 18 238 19 78 19 130 19 266 19 271 20 203 20 474 20 494 21 25 21 429 22 348 22 484 23 388 23 463 24 209 24 243...
output:
19065 967
result:
ok single line: '19065 967'
Test #73:
score: 0
Accepted
time: 416ms
memory: 438496kb
input:
995995 995000 1 516 1 2254 1 3620 2 3500 3 184 3 917 3 1224 3 3467 3 4653 4 537 5 3604 6 687 6 1559 6 4129 7 462 7 1012 7 2094 7 2665 7 4363 7 4473 8 300 8 307 8 1678 8 2921 8 4070 9 3102 9 4561 11 1749 11 3944 11 4927 12 1479 12 3635 13 492 14 1693 14 2362 14 4867 15 2073 15 2166 15 2186 16 1523 16...
output:
19765 706
result:
ok single line: '19765 706'
Test #74:
score: 0
Accepted
time: 230ms
memory: 358508kb
input:
999905 196061 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6...
output:
0 1
result:
ok single line: '0 1'
Test #75:
score: 0
Accepted
time: 219ms
memory: 358512kb
input:
999905 196061 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6...
output:
0 0
result:
ok single line: '0 0'
Test #76:
score: 0
Accepted
time: 248ms
memory: 445096kb
input:
999995 833331 1 2 2 3 3 4 4 5 5 1 1 833331 6 7 7 8 8 9 9 10 10 6 6 833331 11 12 12 13 13 14 14 15 15 11 11 833331 16 17 17 18 18 19 19 20 20 16 16 833331 21 22 22 23 23 24 24 25 25 21 21 833331 26 27 27 28 28 29 29 30 30 26 26 833331 31 32 32 33 33 34 34 35 35 31 31 833331 36 37 37 38 38 39 39 40 40...
output:
1 0
result:
ok single line: '1 0'