QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455043#7769. Axium CrisisHuTao0 2711ms237556kbC++143.8kb2024-06-25 18:15:012024-06-25 18:15:02

Judging History

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

  • [2024-06-25 18:15:02]
  • 评测
  • 测评结果:0
  • 用时:2711ms
  • 内存:237556kb
  • [2024-06-25 18:15:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

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

mt19937 mrand(1719308509);
int n, u[N], v[N], w[N];
int g[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)
{
    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(g[u][v] && v != fa)
        {
            tmp[le] = g[u][v] & 1;
            DFS(v, u, fr, st | (1 << ((g[u][v] >> 1) - 1)), le + 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);
    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]);
    // puts("#");
    // for(int i = 1; i <= m; i ++ )
    // {
    //     for(int j = 0; j < l[p[i]]; j ++ ) printf("%d", s[p[i]][j]);
    //     puts("");
    // }
}

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 ++ )
    {
        // printf("*%d\n", e[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 void GetPath()
{
    if(ans < f[m][(1 << (n - 1)) - 1]) return ;
    ans = f[m][(1 << (n - 1)) - 1];
    for(int i = 1; i < n; i ++ ) answ[i] = g[u[i]][v[i]];
    for(int i = m, j = (1 << (n - 1)) - 1; i >= 0; )
    {
        if(fr[i][j] == -1) i -- ;
        else ansp[ ++ ansc] = c[i], j ^= e[i], i = fr[i][j];
    }
}

inline void DFS(int i, int dep)
{
    if(i == n)
    {
        GetStrings();
        DP();
        GetPath();
        return ;
    }
    if(w[i] < 2)
    {
        g[u[i]][v[i]] = g[v[i]][u[i]] = (i << 1) | w[i];
        DFS(i + 1, dep);
    }
    else if(dep < 2)
    {
        g[u[i]][v[i]] = g[v[i]][u[i]] = (i << 1);
        DFS(i + 1, dep + 1);
        g[u[i]][v[i]] = g[v[i]][u[i]] = (i << 1) | 1;
        DFS(i + 1, dep + 1);
    }
    else
    {
        g[u[i]][v[i]] = g[v[i]][u[i]] = (i << 1) | (mrand() & 1);
        DFS(i + 1, dep + 1);
    }
}

int main()
{
    int T;
    scanf("%d%*d", &T);
    puts("0");
    int flag = 0;
    while(T -- )
    {
        memset(g, 0, sizeof g);
        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] ++ ;
        DFS(1, 0);
        printf("%d\n", n - ans);
        if(ans > n) flag = 25 - T;
    }
    if(flag) printf("!%d\n", flag);
    // printf("!%llu\n", time(0));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 18156kb

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:

0
3
4
4
4
4
3
4
4
4
4
3
4
4
4
4
4
4
4
3
4
4
3
4
4
4
3
4
4
4
-4
3
4
4
3
4
4
4
4
4
4
4
3
4
4
3
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
4
3
4
4
3
4
4
2
4
4
3
3
4
3
3
4
4
3
4
3
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
3
4
3
4
4
3
4
3
4
4
4
4
3
4
4
4
4
3
4
4
4
3
4
4
4
4
4
4
4
4
3
4
4
4
3
4
4
4
4
4
3
4
4...

result:

wrong answer Integer -4 violates the range [1, 4]

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 6ms
memory: 63352kb

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:

0
4
4
4
4
4
3
3
4
6
4
4
4
4
5
4
4
3
3
4
5
3
3
4
4
5
4
3
4
4
4
3
3
5
4
4
4
4
3
3
4
4
4
5
-9
4
4
4
3
4
6
4
4
6
4
4
4
4
4
3
5
4
4
4
3
4
6
4
3
3
4
4
4
4
6
4
3
4
3
4
3
3
4
4
6
4
4
6
3
6
4
4
5
4
4
4
3
3
4
6
4
4
4
6
4
4
3
4
3
4
3
6
3
4
6
4
3
4
6
3
6
4
6
4
4
4
3
7
4
4
4
3
4
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3...

result:

wrong answer Integer -9 violates the range [1, 4]

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 660ms
memory: 236636kb

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:

0
3
8
8
4
8
7
5
7
11
4
8
4
8
10
5
6
7
5
3
11
6
9
6
6
8
8
5
6
4
5
11
4
5
9
6
9
8
8
4
4
8
11
8
-42
4
8
7
4
11
7
7
6
7
8
8
8
6
4
8
8
7
7
8
11
8
5
8
4
7
5
7
7
4
6
5
8
5
3
5
8
7
8
5
8
4
5
4
5
4
6
8
5
6
5
5
5
7
5
8
7
6
3
7
7
8
7
5
4
5
5
4
11
6
8
7
6
5
3
6
6
7
8
8
4
6
5
3
3
8
3
7
7
5
7
3
11
3
4
8
6
4
5
4
5...

result:

wrong answer Integer -42 violates the range [1, 7]

Subtask #8:

score: 0
Wrong Answer

Test #14:

score: 12
Acceptable Answer
time: 2664ms
memory: 236464kb

input:

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

output:

0
7
8
8
8
9
6
7
6
6
10
8
7
6
6
9
6
7
8
11
8
9
8
8
8
6
7
7
11
6
5
7
8
8
7
6
9
7
7
11
8
7
8
6
7
10
6
8
6
7
7
7
7
8
7
9
11
8
7
7
7
11
8
8
7
6
6
7
8
7
8
7
6
7
8
7
11
11
6
7
7
8
8
7
6
8
8
8
9
7
7
8
6
7
7
7
11
6
7
6
8
8
8
8
7
5
6
7
6
7
7
7
8
6
8
8
5
7
8
7
6
7
8
7
6
7
11
10
8
7
8
8
6
6
11
7
7
11
7
10
7
9
7...

result:

points 0.80 Partially Accepted. You Got 80% score.

Test #15:

score: 0
Wrong Answer
time: 2711ms
memory: 237556kb

input:

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

output:

0
8
8
6
6
7
7
6
8
11
8
8
8
6
6
8
9
8
8
8
7
5
11
8
6
8
8
11
6
8
7
8
14
10
8
7
8
7
8
7
6
7
8
8
7
6
6
9
4
7
8
7
10
6
7
8
11
8
8
7
8
8
7
7
10
5
6
7
6
7
13
8
6
7
8
8
7
8
6
11
8
7
11
10
10
11
7
7
5
8
8
8
8
7
8
7
6
10
7
6
5
8
7
7
6
7
6
10
7
8
7
8
6
6
7
6
7
8
8
5
8
8
9
8
7
5
6
7
6
8
7
8
10
6
7
8
7
5
7
8
8
8...

result:

wrong answer Wrong Answer.

Subtask #9:

score: 0
Skipped

Dependency #6:

0%

Subtask #10:

score: 0
Skipped

Dependency #5:

0%