QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#814632 | #9866. Extracting Weights | Nightsky | WA | 1ms | 3836kb | C++20 | 2.8kb | 2024-12-14 19:00:50 | 2024-12-14 19:00:51 |
Judging History
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[u] = 1,u = f[u];
while(v != lca) mat[v] = 1,v = f[v];
mat[lca] = 1;
}
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 = 1; i <= n; ++i) printf("%d ",ret[MAXN]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3836kb
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 "!"