QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#814646#9866. Extracting WeightsNightskyWA 1ms3828kbC++203.0kb2024-12-14 19:09:342024-12-14 19:09:35

Judging History

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

  • [2024-12-14 19:09:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-12-14 19:09:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 255;
int n,k,f[MAXN],totdfn,dfn[MAXN],st[MAXN][12],lg[MAXN],dep[MAXN];
int dot[MAXN][2],cnt,ret[MAXN];
vector <int> e[MAXN];
bitset<MAXN> mat[MAXN],cur;
int Get(int x,int y)
{
    if(dfn[x] < dfn[y]) return x;
    return y;
}
void dfs(int p,int fa)
{
    dfn[p] = ++totdfn;f[p] = fa;st[dfn[p]][0] = fa;dep[p] = dep[fa] + 1;
    for(int v : e[p])
    {
        if(v == fa) continue;
        dfs(v,p);
    }
}
int LCA(int u,int v)
{
    if(u == v) return u;
    if(dfn[u] > dfn[v]) swap(dfn[u],dfn[v]);
    int k = lg[dfn[v] - dfn[u]];
    return Get(st[dfn[u] + 1][k],st[dfn[v] - (1 << k) + 1][k]);
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i = 1; i < n; ++i)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for(int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
    dfs(1,0);
    for(int j = 1; j <= lg[n]; ++j)
        for(int i = 1; i + (1 << j) - 1 <= n; ++i)
            st[i][j] = Get(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
    cnt = 1;mat[1][1] = 1;dot[1][0] = dot[1][1] = 1;
    for(int u = 1; u <= n; ++u)
    {
        for(int v = u + 1; v <= n; ++v)
        {
            int lca = LCA(u,v);
            if(dep[u] + dep[v] - 2 * dep[lca] != k) continue;
            cur.reset();
            int x = u;
            while(x != lca) cur[x] = 1,x = f[x];
            x = v;
            while(x != lca) cur[x] = 1,x = f[x];
            cur[lca] = 1;
            for(int i = 1; i <= n; ++i)
            {
                if(cur[i])
                {
                    if(dot[i][0]) cur ^= mat[i];
                    else
                    {
                        ++cnt;
                        mat[i] = cur;
                        dot[i][0] = u,dot[i][1] = v;
                        break;
                    }
                }
            }
        }
    }
    if(cnt < n)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n? ");
    for(int i = 2; i <= n; ++i)
        printf("%d %d ",dot[i][0],dot[i][1]);
    printf("\n");
    fflush(stdout);
    for(int i = 1; i <= n; ++i)mat[i].reset();
    ret[1] = 0;
    for(int i = 2; i <= n; ++i) scanf("%d",&ret[i]);
    for(int i = 1; i <= n; ++i)
    {
        int u = dot[i][0],v = dot[i][1],lca = LCA(u,v);
        while(u != lca) mat[i][u] = 1,u = f[u];
        while(v != lca) mat[i][v] = 1,v = f[v];
        mat[i][lca] = 1;
    }

    // for(int i = 1; i <= n; ++i,printf("\n"))
    //     for(int j = 1; j <= n; ++j)
    //         printf("%d ",mat[i][j] ? 1 : 0);

    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n ;++j)
        {
            if(i != j && mat[j][i])
            {
                mat[j] ^= mat[i];
                ret[j] ^= ret[i];
            }
        }
    }
    printf("! ");
    for(int i = 2; i <= n; ++i) printf("%d ",ret[i]);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3828kb

input:

4 1
1 2
2 3
2 4
-1

output:

YES
? 1 2 2 3 2 4 

result:

wrong answer Token "3" doesn't correspond to pattern "!"