QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303371 | #7769. Axium Crisis | myee | 0 | 823ms | 33152kb | C++11 | 2.5kb | 2024-01-12 11:16:36 | 2024-01-12 11:16:36 |
Judging History
answer
// 那就是希望。
// 即便需要取模,也是光明。
#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
T ans=1%mod;
while(index)
{
if(index&1)ans=ans*base%mod;
base=base*base%mod,index>>=1;
}
return ans;
}
// Your shadow Gets in the way of my light
uint U[18],V[18],W[18];
std::vector<uint>E[18];
uint End[1u<<18|1],S[1u<<20|1],Last[1u<<20|1],cnt;
voi dfs0(uint p,uint a,uint b)
{
if(b)Last[cnt]=End[a],S[cnt]=b,End[a]=cnt++;
for(auto e:E[p])if(!(b>>e&1))
{
if(W[e]!=1)dfs0(U[e]^V[e]^p,a<<1,b|1u<<e);
if(W[e])dfs0(U[e]^V[e]^p,a<<1|1,b|1u<<e);
}
}
uint R[1u<<17|1],Dp[18][1u<<17|1],n;bol Upd[18][1u<<17|1];
uint Q[18][1u<<17|1],Qc[18];
voi tryupd(uint d,uint s,uint v)
{
if(_max(Dp[d][s],v))
{
if(d+R[s]<v)R[s]=v-d;
if(d&&!Upd[d][s])Upd[d][s]=true,Q[d][Qc[d]++]=s;
}
}
voi dfs(uint d,uint s)
{
for(uint e=End[s|1u<<d];~e;e=Last[e])for(uint t=(1u<<(n-1))-1;~t;t--)t&=~S[e],tryupd(d,S[e]|t,R[t]+d);
if(d<n-1)dfs(d+1,s),dfs(d+1,s|1u<<d);
while(Qc[d])Qc[d]--,Upd[d][Q[d][Qc[d]]]=false,tryupd(d-1,Q[d][Qc[d]],Dp[d][Q[d][Qc[d]]]);
}
voi solve()
{
scanf("%u",&n);for(uint i=0;i<n;i++)E[i].clear();
for(uint i=0;i<n-1;i++)scanf("%u%u%u",U+i,V+i,W+i),E[U[i]].push_back(i),E[V[i]].push_back(i);
for(uint i=0;i<(1u<<n);i++)End[i]=-1;
cnt=0;for(uint i=0;i<n;i++)dfs0(i,1,0);
for(uint i=0;i<n;i++)for(uint j=0;j<(1u<<(n-1));j++)Dp[i][j]=0;
for(uint i=0;i<(1u<<(n-1));i++)R[i]=0;
dfs(0,0),printf("%u\n",1+Dp[(1u<<(n-1))-1]);
}
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
freopen("QAQ.out","w",stdout);
#endif
uint t;scanf("%u%*u",&t),puts("0");
while(t--)solve();
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: 0ms
memory: 12148kb
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 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 208449840 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 210547008 208449840 210547008 210547008 210547008 210547008 210547008 210547008 210547008 21054700...
result:
wrong answer Integer 210547008 violates the range [1, 4]
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 6ms
memory: 18272kb
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 2665410880 2665410880 2665410880 2665410880 2665410880 2665410880 2665410880 2665410880 2677993888 2665410880 2665410880 2665410880 2665410880 2677993888 2665410880 2665410880 2665410880 2663313712 2665410880 2677993888 2665410880 2665410880 2665410880 2665410880 2677993888 2665410880 2677993888 2...
result:
wrong output format Expected int32, but "2665410880" found
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: 148ms
memory: 27912kb
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 1119269152 1119269152 649503520 649503520 1119269152 615948832 590782816 615948832 1119269152 649503520 649503520 1119269152 649503520 1119269152 649503520 649503520 615948832 649503520 599171488 1119269152 1119269152 1119269152 599171488 615948832 649503520 649503520 1119269152 599171488 61594883...
result:
wrong answer Integer 1119269152 violates the range [1, 11]
Subtask #8:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 823ms
memory: 33152kb
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 3884077856 3884077856 3884077856 3884077856 58876192 3884077856 3817001248 3833745824 3850523168 58876192 3884077856 3884077856 3850523168 3850523168 58876192 3833745824 3884077856 3884077856 58876192 3884077856 58876192 3884077856 3884077856 3884077856 3884077856 3884077856 3850523168 58876192 38...
result:
wrong output format Expected int32, but "3884077856" found
Subtask #9:
score: 0
Skipped
Dependency #6:
0%
Subtask #10:
score: 0
Skipped
Dependency #5:
0%