QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#382813#7769. Axium Crisisyyyyxh0 1399ms59880kbC++141.9kb2024-04-08 19:21:332024-04-08 19:21:33

Judging History

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

  • [2024-04-08 19:21:33]
  • 评测
  • 测评结果:0
  • 用时:1399ms
  • 内存:59880kb
  • [2024-04-08 19:21:33]
  • 提交

answer

#include <cstdio>
#include <vector>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=20,T=2000003;
typedef pair<int,int> pii;
int n,rt,MskLim;
int hd[N],ver[N<<1],nxt[N<<1],val[N<<1],tot;
void add(int u,int v,int w){
	nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;val[tot]=w;
}
int tr[T][2],tnum;
int w[N];
struct path{
	int u,v,msk;
	path(int U,int V,int Msk):u(U),v(V),msk(Msk){}
};
vector<path> vec[T];
void dfs(int u,int fa,int msk,int p){
	if(fa) vec[p].emplace_back(rt,u,msk);
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		int id=(i-1)>>1;
		if(val[i]!=1){
			if(!tr[p][0]) tr[p][0]=++tnum;
			dfs(v,u,msk|(1<<id),tr[p][0]);
		}
		if(val[i]!=0){
			if(!tr[p][1]) tr[p][1]=++tnum;
			dfs(v,u,msk|(1<<id),tr[p][1]);
		}
	}
}
int f[N][1<<17];
inline void chmx(int &x,int v){(x<v)&&(x=v);}
void sub(int p,int d){
	if(!p) return;
	for(auto [u,v,msk]:vec[p])
		for(int i=msk;i<MskLim;i=(i+1)|msk) chmx(f[d-1][i],f[d][i]);
	sub(tr[p][0],d);
	sub(tr[p][1],d);
}
void trav(int p,int d){
	if(!p) return;
	for(auto [u,v,msk]:vec[p])
		for(int i=msk;i<MskLim;i=(i+1)|msk)
			for(int j=0;j<n;++j) chmx(f[d][i],f[j][i^msk]+d-j);
	trav(tr[p][0],d+1);
	trav(tr[p][1],d+1);
	if(d) sub(p,d);
}
void solve(){
	n=read();tnum=1;MskLim=1<<(n-1);
	for(int i=1;i<n;++i){
		int u=read()+1,v=read()+1;w[i]=read();
		add(u,v,w[i]);add(v,u,w[i]);
	}
	for(rt=1;rt<=n;++rt) dfs(rt,0,0,1);
	for(int i=0;i<n;++i)
		for(int s=0;s<MskLim;++s) f[i][s]=!i;
	trav(1,0);
	printf("%d\n",f[0][MskLim-1]);
	for(int i=1;i<=n;++i) hd[i]=0;
	while(tot) ver[tot]=nxt[tot]=val[tot]=0,--tot;
	for(int i=1;i<=tnum;++i) tr[i][0]=tr[i][1]=0,vec[i].clear();
}
int main(){
	int tc=read();read();
	while(tc--) solve();
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 50720kb

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:

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
4
...

result:

wrong answer Integer 3 violates the range [0, 1]

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 8ms
memory: 50768kb

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:

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
4
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
4
...

result:

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

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: 1399ms
memory: 59880kb

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:

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
6
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
6
7...

result:

wrong answer Integer 3 violates the range [0, 1]

Subtask #8:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

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:

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
6...

result:


Subtask #9:

score: 0
Skipped

Dependency #6:

0%

Subtask #10:

score: 0
Skipped

Dependency #5:

0%