QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275471 | #7769. Axium Crisis | grass8cow | 0 | 7720ms | 70088kb | C++17 | 1.9kb | 2023-12-04 19:01:31 | 2023-12-04 19:01:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
int oi[18][18],wc[18];
vector<int>g[18];
#define pb push_back
vector<int>st[1<<20];
void dfs(int x,int f,int S,int u){
if(f!=-1)st[u].pb(S);
for(int v:g[x])if(v!=f){
int w=oi[x][v];
if(wc[w]!=1)dfs(v,x,S|(1<<w),u<<1);
if(wc[w]!=0)dfs(v,x,S|(1<<w),u<<1|1);
}
}
int js[1<<21],E,le[1<<21],sv[1<<21];
void pr(int x,int d){
if(d==n)return;
for(int o:st[x])
js[++E]=o,le[E]=d,sv[E]=x;
pr(x<<1,d+1),pr(x<<1|1,d+1);
}
const int I=1e9;
int dp[1<<17][20];
vector<int>o[20];
void ad(int &x,int y){x=max(x,y);}
int jb(int u,int v){
while(u!=v){
if(u>v)swap(u,v);
v>>=1;
}
int d=0;
while(u>1)u>>=1,d++;
return d;
}
void sol(){
memset(oi,0,sizeof(oi));
scanf("%d",&n);
for(int i=0;i<(1<<n);i++)st[i].clear();
for(int i=0;i<n;i++)g[i].clear();
for(int i=0,u,v;i+1<n;i++){
scanf("%d%d%d",&u,&v,&wc[i]);
oi[u][v]=oi[v][u]=i;
g[u].pb(v),g[v].pb(u);
}
for(int i=0;i<n;i++)dfs(i,-1,0,1);
E=0,pr(1,0);n--;
for(int s=0;s<(1<<n);s++)for(int i=0;i<=n;i++)dp[s][i]=-1;
for(int i=0;i<=n;i++)o[i].clear();
dp[0][0]=0,o[0].pb(0);
for(int i=1;i<=E;i++){
if(i>1){
int lc=jb(sv[i],sv[i-1]);
for(int j=lc+1;j<=n;j++)if(!o[j].empty()){
for(int so:o[j]){
if(dp[so][lc]<0)dp[so][lc]=dp[so][j],o[lc].pb(so);
else ad(dp[so][lc],dp[so][j]);
dp[so][j]=-1;
}
o[j].clear();
}
}
int S=((1<<n)-1)^js[i],s2=S;
while(1){
for(int j=0;j<=n;j++)if(dp[s2][j]>=0){
int zd=dp[s2][j]+le[i]-j;
if(dp[js[i]|s2][le[i]]<0)dp[js[i]|s2][le[i]]=zd,o[le[i]].pb(js[i]|s2);
else ad(dp[js[i]|s2][le[i]],zd);
}
if(!s2)break;s2=(s2-1)&S;
}
}
int ans=-1;
for(int s=0;s<(1<<n);s++)for(int i=0;i<=n;i++)ad(ans,dp[s][i]);
printf("0\n%d\n",ans+1);
}
int main(){
int T,tt;
scanf("%d%d",&T,&tt);while(T--)sol();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 34648kb
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 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 3 0 4 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 3 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 3 0 3 0 4 0 3 0 4 0 4 0 3 0 4 0 4 ...
result:
wrong answer Integer 0 violates the range [1, 4]
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 9ms
memory: 36244kb
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 0 4 0 4 0 4 0 4 0 3 0 3 0 4 0 6 0 4 0 4 0 4 0 4 0 5 0 4 0 4 0 3 0 3 0 4 0 5 0 3 0 3 0 4 0 4 0 5 0 4 0 3 0 4 0 4 0 4 0 3 0 3 0 5 0 4 0 4 0 4 0 4 0 3 0 3 0 4 0 4 0 4 0 5 0 4 0 4 0 4 0 4 0 3 0 4 0 6 0 4 0 4 0 6 0 4 0 4 0 4 0 4 0 4 0 3 0 5 0 4 0 4 0 4 0 3 0 4 0 6 0 4 0 3 0 3 0 4 0 4 0 4 0 4 0 6 0 4 ...
result:
wrong answer Integer 0 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: 981ms
memory: 46356kb
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 0 8 0 8 0 4 0 8 0 7 0 5 0 7 0 11 0 4 0 8 0 4 0 8 0 10 0 5 0 6 0 7 0 5 0 3 0 11 0 6 0 9 0 6 0 6 0 8 0 8 0 5 0 6 0 4 0 5 0 11 0 4 0 5 0 9 0 6 0 9 0 8 0 8 0 4 0 4 0 8 0 11 0 8 0 6 0 4 0 8 0 7 0 4 0 11 0 7 0 7 0 6 0 7 0 8 0 8 0 8 0 6 0 4 0 8 0 8 0 7 0 7 0 8 0 11 0 8 0 5 0 8 0 4 0 7 0 5 0 7 0 7 0 4 0...
result:
wrong answer Integer 0 violates the range [1, 11]
Subtask #8:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 7720ms
memory: 70088kb
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 0 8 0 8 0 8 0 9 0 6 0 7 0 6 0 6 0 10 0 8 0 7 0 6 0 6 0 9 0 6 0 7 0 8 0 11 0 8 0 9 0 8 0 8 0 8 0 6 0 7 0 7 0 11 0 6 0 5 0 7 0 8 0 8 0 7 0 6 0 9 0 7 0 7 0 11 0 8 0 7 0 8 0 6 0 7 0 10 0 6 0 8 0 6 0 7 0 7 0 7 0 7 0 8 0 7 0 9 0 11 0 8 0 7 0 7 0 7 0 11 0 8 0 8 0 7 0 6 0 6 0 7 0 8 0 7 0 8 0 7 0 6 0 7 0...
result:
wrong answer Integer 0 violates the range [1, 8]
Subtask #9:
score: 0
Skipped
Dependency #6:
0%
Subtask #10:
score: 0
Skipped
Dependency #5:
0%