QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455063#7769. Axium CrisisHuTao100 ✓2489ms1190588kbC++144.2kb2024-06-25 19:11:402024-06-25 19:11:40

Judging History

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

  • [2024-06-25 19:11:40]
  • 评测
  • 测评结果:100
  • 用时:2489ms
  • 内存:1190588kb
  • [2024-06-25 19:11:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 20, M = 1240, T = 262150;
const short INF = 0x3f3f;

int n, u[N], v[N], w[N];
int g[N][N], gg[N][N];
char tmp[N], s[M][N];
int m, l[M], e[M], c[M], p[M], h[M], lvl[M];
short f[M][T], fr[M][T];
int sta[N], tt;
int ans, answ[N], ansc, ansp[N];

inline void DFS(int u, int fa, int fr, int st, int le, int count)
{
    if(st)
    {
        m ++ ;
        e[m] = st, l[m] = le, c[m] = fr * (n + 1) + u;
        for(int i = 0; i < le; i ++ ) s[m][i] = tmp[i];
    }
    for(int v = 1; v <= n; v ++ )
        if(gg[u][v] && v != fa)
        {
            if(g[u][v] < 2)
            {
                tmp[le] = g[u][v];
                DFS(v, u, fr, st | (1 << (gg[u][v] - 1)), le + 1, count);
            }
            else if(count < 2)
            {
                tmp[le] = 0;
                DFS(v, u, fr, st | (1 << (gg[u][v] - 1)), le + 1, count + 1);
                tmp[le] = 1;
                DFS(v, u, fr, st | (1 << (gg[u][v] - 1)), le + 1, count + 1);
            }
            else
            {
                tmp[le] = 1;
                DFS(v, u, fr, st | (1 << (gg[u][v] - 1)), le + 1, count + 1);
            }
        }
}
inline bool Cmp(int i, int j)
{
    for(int k = 0; k < min(l[i], l[j]); k ++ )
        if(s[i][k] != s[j][k])
            return s[i][k] < s[j][k];
    return l[i] < l[j];
}
inline int LCP(int i, int j)
{
    for(int k = 0; k < min(l[i], l[j]); k ++ )
        if(s[i][k] != s[j][k])
            return k;
    return min(l[i], l[j]);
}
inline void Sort(int l[])
{
    for(int i = 1; i <= m; i ++ ) lvl[i] = l[p[i]];
    for(int i = 1; i <= m; i ++ ) l[i] = lvl[i];
}
inline void GetStrings()
{
    m = 0;
    for(int i = 1; i <= n; i ++ ) DFS(i, 0, i, 0, 0, 0);
    for(int i = 1; i <= m; i ++ ) p[i] = i;
    sort(p + 1, p + m + 1, Cmp);
    Sort(e), Sort(c);
    for(int i = 1; i < m; i ++ ) h[i] = LCP(p[i], p[i + 1]);
}

inline void DP()
{
    int S = (1 << (n - 1)) - 1;
    for(int j = 0; j <= S; j ++ ) f[0][j] = INF;
    f[0][0] = 0, fr[0][0] = 0;
    tt = 0;
    for(int i = 1; i <= m; i ++ )
    {
        for(int j = 0; j <= S; j ++ )
            f[i][j] = f[i - 1][j], fr[i][j] = -1;
        while(tt && h[sta[tt]] >= h[i - 1]) tt -- ;
        sta[ ++ tt] = i - 1;
        for(int j = 1; j <= tt; j ++ )
        {
            int k = S ^ e[i];
            do{
                if(f[i][k | e[i]] > f[sta[j]][k] + h[sta[j]])
                {
                    f[i][k | e[i]] = f[sta[j]][k] + h[sta[j]];
                    fr[i][k | e[i]] = sta[j];
                }
                k = (k - 1) & (S ^ e[i]);
            }while(k != (S ^ e[i]));
        }
    }
}

inline bool FindPath(int u, int fa, int t, int st, int dep)
{
    if(u == t) return 1;
    for(int v = 1; v <= n; v ++ )
        if(v != fa && gg[u][v])
        {
            if(FindPath(v, u, t, st, dep + 1))
            {
                answ[gg[u][v]] = st >> dep & 1;
                return 1;
            }
        }
    return 0;
}
inline void GetPath()
{
    ans = f[m][(1 << (n - 1)) - 1];
    ansc = 0;
    for(int i = m, j = (1 << (n - 1)) - 1; i; )
    {
        if(fr[i][j] == -1) i -- ;
        else
        {
            int st = 0;
            for(int j = 0; j < l[p[i]]; j ++ ) st = st | (s[p[i]][j] << j);
            FindPath(c[i] / (n + 1), 0, c[i] % (n + 1), st, 0);
            ansp[ ++ ansc] = c[i], st = fr[i][j], j ^= e[i], i = st;
        }
    }
}

int main()
{
    int T;
    scanf("%d%*d", &T);
    puts("1");
    while(T -- )
    {
        memset(g, 0, sizeof g);
        memset(gg, 0, sizeof gg);
        ans = INF;
        scanf("%d", &n);
        for(int i = 1; i < n; i ++ )
        {
            scanf("%d%d%d", &u[i], &v[i], &w[i]);
            u[i] ++ , v[i] ++ ;
            g[u[i]][v[i]] = g[v[i]][u[i]] = w[i];
            gg[u[i]][v[i]] = gg[v[i]][u[i]] = i;
        }
        GetStrings(), DP(), GetPath();
        printf("%d\n", n - ans);
        printf("%d\n", ansc);
        for(int i = 1; i < n; i ++ ) printf("%d ", answ[i]);
        puts("");
        for(int i = 1; i <= ansc; i ++ ) printf("%d %d\n", ansp[i] / (n + 1) - 1, ansp[i] % (n + 1) - 1);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 42912kb

input:

1000 0
4
0 2 0
2 3 0
2 1 0
4
3 2 1
0 2 1
1 2 2
4
0 2 2
0 1 0
3 0 0
4
1 2 1
3 2 0
2 0 1
4
0 2 0
0 3 0
2 1 0
4
0 2 1
0 3 1
0 1 1
4
3 1 0
2 1 2
3 0 2
4
3 1 1
3 0 1
2 3 0
4
1 0 0
2 0 2
2 3 2
4
1 2 0
3 0 0
2 3 2
3
2 1 0
0 2 1
4
3 0 1
1 2 1
2 3 0
4
2 1 0
3 0 1
1 0 1
4
3 2 1
3 1 1
0 1 1
4
1 2 1
1 3 0
3 0 1...

output:

1
3
2
0 0 0 
0 1
2 3
4
2
1 1 0 
0 2
1 3
4
2
1 0 0 
2 0
3 1
4
2
1 0 1 
0 2
3 1
4
1
0 0 0 
1 3
3
2
1 1 1 
1 2
0 3
4
1
0 0 0 
2 0
4
2
1 1 0 
0 3
2 1
4
1
0 0 0 
1 3
4
1
0 0 0 
1 0
3
1
0 1 
1 0
4
2
1 1 0 
0 3
3 1
4
1
0 1 1 
2 3
4
1
1 1 1 
0 2
4
2
1 0 1 
0 3
3 2
4
1
1 0 0 
0 1
4
1
0 0 0 
1 2
4
1
0 1 0 
0 ...

result:

ok Accepted. Good Job!

Test #2:

score: 10
Accepted
time: 0ms
memory: 42916kb

input:

1000 0
4
2 0 0
2 1 0
0 3 0
4
2 1 0
2 0 0
1 3 0
4
1 3 0
1 0 0
2 1 0
4
0 1 2
2 1 2
1 3 2
4
0 2 2
3 2 0
1 3 1
4
1 3 0
2 3 0
3 0 0
4
1 2 1
3 0 0
0 2 0
4
3 2 1
2 1 1
0 1 0
4
2 1 0
3 2 0
2 0 0
4
1 3 0
2 3 0
3 0 2
4
2 0 0
3 0 1
1 2 1
4
0 2 2
3 1 2
2 1 2
4
1 3 2
3 0 2
2 0 2
4
2 0 0
2 1 2
2 3 1
4
0 1 2
2 3 1...

output:

1
4
1
0 0 0 
1 3
4
1
0 0 0 
0 3
3
2
0 0 0 
0 2
1 3
4
2
0 1 0 
1 2
0 3
4
1
0 0 1 
0 1
3
2
0 0 0 
0 1
2 3
4
1
1 0 0 
3 1
4
1
1 1 0 
0 3
3
2
0 0 0 
0 1
2 3
4
2
0 0 1 
0 3
1 2
4
2
0 1 1 
0 3
0 1
4
1
1 0 0 
3 0
4
1
1 0 0 
2 1
4
2
0 1 1 
1 2
0 3
4
1
0 1 0 
0 2
3
2
0 0 0 
0 1
2 3
4
1
0 1 0 
2 3
4
1
0 0 0 
...

result:

ok Accepted. Good Job!

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 8ms
memory: 63396kb

input:

3000 3
4
0 1 1
0 3 1
0 2 0
4
3 2 0
0 1 1
1 2 0
4
1 0 0
2 3 1
3 1 0
4
2 1 0
2 0 1
3 0 0
4
2 3 1
3 0 1
2 1 0
4
2 3 1
2 1 1
2 0 1
4
0 2 0
1 0 0
3 0 0
4
3 1 1
0 2 0
2 3 0
6
4 0 0
3 1 1
2 3 0
0 5 1
1 5 0
4
2 3 1
3 0 0
3 1 1
4
0 3 0
1 2 0
0 2 1
4
0 2 1
3 1 0
2 1 1
4
2 0 0
2 3 1
1 3 0
6
3 1 0
3 4 1
4 0 1
2...

output:

1
4
2
1 1 0 
0 1
2 3
4
1
0 1 0 
3 0
4
1
0 1 0 
0 2
4
1
0 1 0 
1 3
4
1
1 1 0 
1 0
3
2
1 1 1 
0 1
2 3
3
2
0 0 0 
1 2
0 3
4
1
1 0 0 
0 1
6
1
0 1 0 1 0 
4 2
4
2
1 0 1 
1 3
0 2
4
1
0 0 1 
1 3
4
1
1 0 1 
3 0
4
1
0 1 0 
0 1
5
3
0 1 1 1 1 
5 1
2 4
1 0
4
2
1 0 0 
0 1
2 3
4
2
1 0 1 
0 2
2 3
3
2
1 1 1 
0 2
1 3...

result:

ok Accepted. Good Job!

Test #4:

score: 10
Accepted
time: 8ms
memory: 63324kb

input:

3000 3
3
0 1 0
1 2 0
4
2 1 1
0 2 0
0 3 1
6
3 4 1
1 4 0
1 5 1
2 1 1
3 0 0
4
0 2 1
1 2 0
1 3 1
4
0 3 1
2 0 1
1 2 0
6
1 2 0
0 3 0
2 5 0
0 2 1
4 2 0
4
2 0 0
2 1 1
3 1 1
4
1 0 1
1 2 0
3 0 1
4
1 3 0
2 1 1
0 2 0
4
1 3 0
2 1 0
1 0 0
4
3 1 0
2 3 0
0 1 1
4
1 0 0
2 0 0
3 0 0
4
2 1 1
1 0 1
2 3 0
4
3 0 1
1 0 0
2...

output:

1
3
1
0 0 
0 2
4
2
1 0 1 
0 3
0 1
6
2
1 0 1 1 0 
1 2
0 5
4
2
1 0 1 
0 2
2 3
4
1
1 1 0 
1 3
5
2
0 0 0 1 0 
5 3
4 1
4
1
0 1 1 
0 3
4
1
1 0 1 
2 3
4
1
0 1 0 
0 3
3
2
0 0 0 
0 2
1 3
4
1
0 0 1 
2 0
3
2
0 0 0 
1 2
0 3
4
1
1 1 0 
3 0
4
1
1 0 0 
1 2
6
1
1 0 0 1 0 
1 3
4
2
0 1 1 
0 3
0 1
4
1
0 1 0 
2 3
4
1
0...

result:

ok Accepted. Good Job!

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 10
Accepted
time: 27ms
memory: 415568kb

input:

3000 4
4
2 0 0
1 2 0
1 3 0
4
1 2 2
0 2 2
3 2 2
4
3 1 2
3 2 0
0 2 0
4
0 3 2
2 1 2
0 1 2
4
0 1 0
3 0 0
0 2 2
4
2 0 0
2 1 0
3 0 0
6
0 3 2
5 0 2
5 2 2
1 4 2
4 3 2
4
0 3 0
3 1 0
0 2 0
4
1 0 2
2 0 2
3 2 2
4
2 1 2
1 0 2
0 3 2
6
5 0 2
0 2 2
0 4 2
1 0 2
0 3 2
6
4 5 2
0 1 2
0 3 2
4 3 2
5 2 2
4
1 3 0
3 2 0
1 0...

output:

1
4
1
0 0 0 
0 3
4
2
0 0 1 
3 2
1 0
4
1
0 0 0 
1 0
4
1
1 0 0 
2 3
4
2
0 0 1 
2 0
3 1
4
1
0 0 0 
1 3
6
1
1 0 0 1 1 
2 1
4
1
0 0 0 
1 2
4
1
0 0 1 
1 3
4
1
0 0 1 
2 3
5
3
0 0 1 0 1 
3 0
5 4
2 1
6
1
0 1 1 1 0 
2 1
4
1
0 0 0 
2 0
6
1
1 1 0 1 0 
5 1
4
1
0 0 0 
0 3
4
1
0 0 0 
1 0
4
3
0 0 0 0 0 
2 0
4 5
4 1...

result:

ok Accepted. Good Job!

Test #6:

score: 10
Accepted
time: 23ms
memory: 415500kb

input:

3000 0
6
1 3 2
0 4 0
1 4 2
3 5 1
0 2 0
6
0 5 0
0 4 1
0 2 0
3 0 0
1 0 0
6
4 1 2
2 1 1
5 0 2
5 3 1
2 3 0
4
2 0 0
1 0 2
1 3 0
4
2 3 1
0 1 1
2 1 0
4
0 3 1
1 0 2
2 3 0
4
1 3 1
2 3 0
0 1 2
6
1 0 1
4 1 1
5 1 1
3 1 1
2 1 2
4
0 3 1
1 3 2
1 2 1
4
1 2 1
0 2 0
3 1 1
6
0 2 1
1 2 1
0 5 0
2 4 1
2 3 1
6
3 2 1
0 2 0...

output:

1
6
1
0 0 0 1 0 
2 5
5
3
0 1 0 0 0 
4 1
5 3
0 2
6
1
0 1 0 1 0 
4 0
4
1
0 0 0 
2 3
4
2
1 1 0 
0 1
1 3
4
1
1 0 0 
1 2
4
1
1 0 0 
2 0
5
3
1 1 1 1 0 
5 3
4 1
2 0
4
2
1 0 1 
0 3
3 2
4
1
1 0 1 
0 3
6
2
1 1 0 1 1 
4 3
5 1
6
2
1 0 1 0 1 
4 0
0 1
4
2
1 0 1 
1 2
0 3
4
1
1 0 0 
3 0
6
1
1 0 0 1 1 
1 3
3
2
0 0 0...

result:

ok Accepted. Good Job!

Subtask #4:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 10
Accepted
time: 55ms
memory: 194292kb

input:

3000 3
8
1 2 1
3 7 0
7 0 1
7 4 0
6 5 0
6 4 1
2 0 0
5
3 1 0
3 2 1
0 1 0
4 0 1
5
3 2 0
4 0 0
4 1 0
2 0 1
6
5 4 1
4 1 1
4 2 1
0 4 1
4 3 1
5
4 1 0
4 3 0
2 1 1
3 0 1
8
3 6 0
1 4 1
2 3 1
0 6 1
0 7 1
2 1 0
7 5 0
8
4 5 0
5 7 0
3 0 0
2 4 1
1 2 0
5 6 0
6 3 1
5
4 1 0
4 0 0
4 3 0
2 4 1
5
1 0 0
1 2 0
2 3 1
0 4 1...

output:

1
8
2
1 0 1 0 0 1 0 
1 7
3 5
5
2
0 1 0 1 
0 4
0 2
5
1
0 0 0 1 
1 3
3
4
1 1 1 1 1 
5 0
2 4
4 1
3 4
5
2
0 0 1 1 
0 3
3 2
8
1
0 1 1 1 1 0 0 
5 4
7
2
0 0 0 1 0 0 1 
0 5
7 1
5
2
0 0 0 1 
2 0
3 1
5
2
0 0 1 1 
0 4
0 3
6
2
1 0 1 0 0 
1 5
2 4
6
2
0 1 1 1 0 
0 4
1 2
5
2
0 0 0 0 1 
1 5
3 2
8
1
0 1 1 0 0 1 0 
1...

result:

ok Accepted. Good Job!

Test #8:

score: 10
Accepted
time: 55ms
memory: 190332kb

input:

3000 3
6
3 1 1
1 4 0
1 0 1
1 2 0
5 1 0
6
0 3 1
2 4 1
1 5 1
1 4 0
4 0 0
6
2 5 0
1 5 1
3 4 0
4 0 0
3 2 1
8
2 5 0
6 7 0
0 3 0
6 0 1
1 4 0
7 5 1
3 4 1
11
7 6 1
3 5 1
2 7 1
7 10 0
1 7 0
8 7 0
9 7 0
4 7 0
5 7 0
0 7 1
6
5 1 1
2 4 1
3 0 1
2 0 0
5 4 0
8
3 1 1
1 6 0
0 7 0
2 7 1
4 5 1
4 3 1
0 6 1
6
0 2 0
1 2 0...

output:

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

result:

ok Accepted. Good Job!

Subtask #5:

score: 10
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 10
Accepted
time: 111ms
memory: 571236kb

input:

3000 4
6
2 5 2
3 4 0
2 1 0
0 1 0
0 3 2
6
2 0 2
1 4 0
5 3 0
0 4 2
0 3 0
8
4 6 2
2 5 2
1 0 2
5 0 2
1 4 2
4 7 2
3 7 2
6
0 4 0
5 2 0
2 1 0
1 0 2
5 3 2
8
5 6 2
6 3 2
6 7 2
7 4 2
2 6 2
1 4 2
0 4 2
6
1 5 0
2 1 0
3 1 0
5 0 0
2 4 0
6
5 1 2
0 5 0
2 4 2
2 5 0
4 3 0
8
7 6 0
6 1 0
2 0 0
7 3 0
3 2 0
4 0 0
5 1 0
6...

output:

1
6
1
0 0 0 0 0 
5 4
6
2
1 0 0 0 0 
0 2
5 1
8
2
1 1 1 1 1 0 0 
6 4
3 2
6
1
0 0 0 0 0 
4 3
7
3
0 1 0 1 0 1 1 
0 4
5 3
2 1
5
2
0 0 0 0 0 
4 0
1 3
6
2
1 0 0 0 0 
5 1
3 0
8
1
0 0 0 0 0 0 0 
5 4
6
1
0 0 0 0 0 
5 2
5
2
0 0 0 0 0 
2 4
0 5
8
2
1 1 1 0 1 1 0 
1 0
5 6
8
2
0 0 1 0 0 0 0 
2 3
7 5
6
1
1 1 0 0 1 ...

result:

ok Accepted. Good Job!

Test #10:

score: 10
Accepted
time: 80ms
memory: 415572kb

input:

3000 0
6
4 0 0
1 4 1
5 3 0
3 2 1
0 5 1
8
1 7 0
6 1 0
4 2 0
4 1 1
5 4 0
4 3 0
0 4 1
8
3 1 0
2 3 0
3 0 0
4 7 0
5 7 0
7 6 0
7 3 0
6
5 2 2
4 0 2
0 3 2
5 4 2
1 3 2
4
2 3 1
3 0 1
1 3 1
5
0 2 1
2 4 0
1 4 2
3 4 0
6
1 0 0
4 2 0
4 5 0
3 5 0
2 0 0
5
0 1 0
0 2 0
0 3 0
0 4 0
6
1 4 1
1 3 1
1 5 1
0 2 0
1 2 0
5
0 2...

output:

1
6
2
0 1 0 1 1 
4 1
4 2
6
4
0 0 0 1 0 0 1 
4 0
2 6
5 3
7 1
4
5
0 0 0 0 0 0 0 
2 5
3 1
0 3
7 6
4 7
6
1
0 1 1 0 1 
2 1
3
2
1 1 1 
0 1
2 3
5
2
1 0 1 0 
4 1
3 0
6
1
0 0 0 0 0 
3 1
3
3
0 0 0 0 
4 3
1 0
0 2
6
2
1 1 1 0 0 
3 4
0 5
5
2
1 0 0 0 
0 1
4 3
5
3
0 1 0 1 0 
3 2
0 5
4 1
6
4
1 1 1 1 1 0 1 
4 2
1 0
...

result:

ok Accepted. Good Job!

Subtask #6:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 10
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1 0 1 
1 2
4 5
7 3
7
2
0 0 0 0 0 1 1 
1 6
0 7
7
3
1 1 0 1 0 1 1 
7 4
6 1
0 5
7
2
1 0 1 1 0 0 
5 2
1 3
7
3
1 0 1 0 0 1 1 
2 1
5 3
4 7
8
5
0 0 1 0 1 0 0 1 1 0 
4 5
9 1
2 7
6 10
3 0
8
2
0 1 0 0 1 0 0 
1 6
0 7
8
1
0 1 1 1 1 0 0 
7 6
7
3
0 0 0 0 1 0 1 
4 7
6 2
0 1...

result:

ok Accepted. Good Job!

Subtask #7:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 650ms
memory: 318036kb

input:

3000 1
11
2 5 0
10 2 0
6 2 0
2 8 0
0 2 0
2 1 0
2 4 0
2 9 0
2 3 0
7 2 0
11
7 8 0
6 4 0
1 6 0
2 8 0
8 0 0
6 3 0
9 5 0
5 8 0
1 2 0
9 10 0
8
1 4 0
2 3 0
6 5 0
6 7 0
2 4 0
7 3 0
1 0 0
8
4 0 0
0 5 0
7 2 0
0 2 0
0 6 0
0 1 0
0 3 0
11
5 1 0
7 2 0
9 2 0
4 9 0
0 2 0
8 5 0
0 6 0
3 6 0
4 10 0
1 7 0
7
6 2 0
0 5 0...

output:

1
3
9
0 0 0 0 0 0 0 0 0 0 
7 9
6 2
2 4
3 2
5 2
2 10
2 8
2 0
1 2
8
4
0 0 0 0 0 0 0 0 0 0 
4 10
8 0
8 7
3 6
8
1
0 0 0 0 0 0 0 
5 0
4
5
0 0 0 0 0 0 0 
7 3
0 1
4 0
5 0
6 0
8
4
0 0 0 0 0 0 0 0 0 0 
8 10
3 6
2 0
6 0
7
1
0 0 0 0 0 0 
3 1
5
1
0 0 0 0 
0 4
7
1
0 0 0 0 0 0 
4 2
11
1
0 0 0 0 0 0 0 0 0 0 
5 7
4...

result:

ok Accepted. Good Job!

Subtask #8:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 2489ms
memory: 1189992kb

input:

3000 2
8
4 7 2
4 3 2
3 2 2
4 5 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7
2
0 1 0 0 1 1 
1 5
3 0
7
3
0 1 1 0 1 0 0 
6 1
4 2
5 7
6
4
0 0 1 0 1 1 0 
2 4
6 0
3 7
1 5
8
2
0 1 1 1 1 0 1 
7 6
3 0
11
1
1 0 1 1 1 1 0 1 1 1 
5 9
8
2
1 0 0 0 1 1 1 
2 6
3 7
8
2
0 0 1 1 1 1 1 
4 6
7 ...

result:

ok Accepted. Good Job!

Test #16:

score: 15
Accepted
time: 2462ms
memory: 1189728kb

input:

3000 2
8
7 2 2
5 2 2
4 2 2
0 2 2
6 2 2
1 2 2
3 2 2
8
6 4 2
4 7 2
0 4 2
3 2 2
3 4 2
5 3 2
5 1 2
8
0 1 2
4 0 2
3 2 2
6 7 2
6 2 2
5 3 2
7 1 2
10
3 1 2
8 3 2
7 3 2
4 3 2
2 3 2
9 3 2
0 3 2
6 3 2
3 5 2
7
2 5 2
3 2 2
5 0 2
2 1 2
6 2 2
4 2 2
8
2 7 2
2 6 2
2 5 2
2 4 2
0 2 2
2 3 2
2 1 2
7
5 2 2
1 5 2
4 2 2
3 ...

output:

1
6
4
0 0 0 0 1 1 0 
6 5
4 1
3 7
2 0
7
3
0 0 1 1 0 1 1 
2 3
6 0
7 1
8
1
0 0 1 1 1 1 1 
4 5
7
5
0 1 1 1 0 1 0 0 0 
8 7
9 5
6 4
2 1
3 0
6
3
0 0 0 1 1 1 
4 2
3 6
0 1
6
4
0 1 0 0 0 0 1 
6 5
4 1
3 7
2 0
7
1
1 1 1 0 0 1 
0 1
6
3
0 0 0 1 1 0 
3 4
5 0
6 1
8
1
1 0 0 1 1 1 1 
2 3
7
1
1 0 1 0 1 1 
5 3
8
2
1 1 ...

result:

ok Accepted. Good Job!

Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 673ms
memory: 321648kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 685ms
memory: 321588kb

input:

3000 3
8
2 7 0
3 4 0
1 0 0
7 5 1
2 3 1
6 5 0
0 4 1
11
10 5 1
2 5 1
5 9 0
5 0 0
4 1 0
3 5 0
5 1 1
6 5 0
7 5 0
8 1 1
8
3 4 1
1 3 1
7 3 0
5 3 0
5 2 0
6 0 0
0 2 1
7
2 5 1
1 3 1
1 5 0
0 6 1
0 2 0
6 4 0
7
0 3 0
2 6 1
0 4 1
5 1 1
4 6 0
1 3 1
11
1 4 0
9 4 0
10 4 1
4 2 0
7 4 0
7 6 1
4 5 0
8 4 1
4 0 0
4 3 1
6...

output:

1
8
1
0 0 0 1 1 0 1 
6 1
8
5
1 1 0 0 0 0 1 0 0 1 
8 6
10 0
9 2
3 7
1 4
8
2
1 1 0 0 0 0 1 
1 7
6 4
7
1
1 1 0 1 0 0 
4 3
7
2
0 1 1 1 0 1 
2 6
6 5
8
5
0 0 1 0 0 1 0 1 0 1 
3 10
6 0
9 8
5 1
4 2
6
2
0 1 1 1 0 
2 0
5 4
7
3
1 0 0 0 0 0 1 
4 5
2 1
0 3
11
1
0 1 0 1 0 1 1 0 0 1 
0 5
7
3
1 0 0 0 1 0 0 
6 4
0 1...

result:

ok Accepted. Good Job!

Subtask #10:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #19:

score: 10
Accepted
time: 1274ms
memory: 1054712kb

input:

3000 0
8
3 2 0
0 2 1
4 1 1
5 4 0
3 6 1
7 5 1
6 1 0
8
3 1 2
4 5 0
1 6 2
5 0 0
3 2 0
7 5 2
2 4 0
8
4 7 1
5 3 0
4 0 1
6 5 1
3 1 2
2 4 1
3 4 2
11
3 2 0
8 2 0
1 5 2
0 8 2
3 9 2
0 7 2
4 3 0
6 9 2
6 5 0
10 9 2
11
10 1 2
8 4 2
8 7 2
0 4 2
8 6 2
3 9 2
2 9 2
2 1 2
0 3 2
5 8 2
7
3 5 0
0 3 1
4 2 0
5 2 1
1 4 1
1...

output:

1
8
2
0 1 1 0 1 1 0 
5 7
5 0
8
2
0 0 0 0 0 1 0 
7 5
0 6
7
3
1 0 1 1 0 1 0 
0 2
3 7
1 6
10
3
0 0 1 0 1 0 0 1 0 1 
9 10
7 1
3 4
11
2
0 1 1 1 1 1 1 0 1 0 
7 5
10 6
7
2
0 1 0 1 1 1 
3 0
3 6
8
1
0 1 0 1 0 1 1 
2 0
8
1
0 0 0 0 1 1 1 
0 1
7
3
1 1 0 1 1 1 0 
6 2
7 3
1 5
7
2
1 1 1 0 1 0 
3 5
1 4
5
1
0 1 0 1 ...

result:

ok Accepted. Good Job!

Test #20:

score: 10
Accepted
time: 1087ms
memory: 928028kb

input:

3000 0
8
0 3 0
7 1 0
0 5 0
1 4 0
2 5 0
6 2 0
4 6 0
8
1 5 0
6 0 1
2 3 1
5 7 1
4 1 1
6 4 0
3 0 0
7
4 0 0
4 6 1
6 5 0
1 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