QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454922#7769. Axium CrisisNKheyuxiang12 2279ms14864kbC++142.1kb2024-06-25 16:42:362024-06-25 16:42:38

Judging History

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

  • [2024-06-25 16:42:38]
  • 评测
  • 测评结果:12
  • 用时:2279ms
  • 内存:14864kb
  • [2024-06-25 16:42:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,cnt;
int E[19][19],id[19][19];
mt19937 rd(time(0));
struct node{
	int eset,num,st,ed;
	int road[19],len;
	void init(int x){
		len=eset=num=0;
		road[0]=st=ed=x;
	}
}path[3005];
bool cmp(node p1,node p2){
	if(p1.num!=p2.num) return p1.num<p2.num;
	if(p1.len!=p2.len) return p1.len<p2.len;
	return p1.eset<p2.eset;
}
void dfs(int u,int fa,node pp,int lim){
	if(u!=pp.st) path[++cnt]=pp;
	for(int v=1;v<=n;v++){
		if(id[u][v]==0||v==fa) continue;
		node go=pp;
		go.road[++go.len]=v;
		go.ed=v;
		go.eset+=(1<<(id[u][v]-1));
		if(lim==0){
			int c=E[u][v];
			if(c==2) c=rd()%2;
			go.num+=c*(1<<(n-go.len));
			dfs(v,u,go,0);
		}
		else{
			if(E[u][v]!=1) dfs(v,u,go,lim-1);
			go.num+=(1<<(n-go.len));
			if(E[u][v]!=0) dfs(v,u,go,lim-1);
		}
	}
}
int f[1<<18|1][19],lcp[3005];
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) E[i][j]=id[i][j]=0;
	for(int i=1;i<n;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		u++,v++;
		E[u][v]=E[v][u]=w;
		id[u][v]=id[v][u]=i;
	}
	cnt=0;
	for(int i=1;i<=n;i++){
		node pp;
		pp.init(i);
		dfs(i,0,pp,2);
	}
	sort(path+1,path+cnt+1,cmp);
	for(int i=2;i<=cnt;i++){
		lcp[i]=0;
		for(int j=1;j<=min(path[i-1].len,path[i].len);j++){
			if(path[i-1].num/(1<<(n-j))!=path[i].num/(1<<(n-j))) break;
			lcp[i]=j;
		}
	}
	lcp[1]=n;
	int lim=(1<<(n-1));
	for(int i=0;i<lim;i++)
		for(int j=0;j<n;j++) f[i][j]=-1e9;
	for(int i=1;i<=cnt;i++){
		if(path[i].num==path[i-1].num&&path[i].eset==path[i-1].eset) continue;
		int s=path[i].eset,len=path[i].len;
		for(int j=lim;j>0;j--){
			for(int k=lcp[i]+1;k<path[i-1].len;k++){
				f[j][lcp[i]]=max(f[j][lcp[i]],f[j][k]);
				f[j][k]=-1e9;
			}
			if((j&s)==0){
				for(int k=0;k<=lcp[i];k++)
					f[j+s][len]=max(f[j+s][len],f[j][k]+len-k);
			}
		}
		f[s][len]=max(f[s][len],len);
	}
	int ans=0;
	for(int j=1;j<lim;j++)
		for(int k=0;k<n;k++)
			ans=max(ans,f[j][k]);
	printf("%d\n",ans+1);
}
int main(){
	int t,o;
	scanf("%d%d",&t,&o);
	printf("0\n");
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Acceptable Answer

Test #1:

score: 8
Acceptable Answer
time: 2ms
memory: 3868kb

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

result:

points 0.80 Partially Accepted. You Got 80% score.

Test #2:

score: 8
Acceptable Answer
time: 2ms
memory: 3936kb

input:

1000 0
4
2 0 0
2 1 0
0 3 0
4
2 1 0
2 0 0
1 3 0
4
1 3 0
1 0 0
2 1 0
4
0 1 2
2 1 2
1 3 2
4
0 2 2
3 2 0
1 3 1
4
1 3 0
2 3 0
3 0 0
4
1 2 1
3 0 0
0 2 0
4
3 2 1
2 1 1
0 1 0
4
2 1 0
3 2 0
2 0 0
4
1 3 0
2 3 0
3 0 2
4
2 0 0
3 0 1
1 2 1
4
0 2 2
3 1 2
2 1 2
4
1 3 2
3 0 2
2 0 2
4
2 0 0
2 1 2
2 3 1
4
0 1 2
2 3 1...

output:

0
4
4
3
4
4
3
4
4
3
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
3
4
3
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
3
4
4
4
4
4
3
4
4
4
4
4
4
3
4
3
3
4
3
4
3
4
4
4
4
3
4
4
4
4
3
4
3
4
4
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
4
4
3
4
4
3
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
...

result:

points 0.80 Partially Accepted. You Got 80% score.

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 7ms
memory: 5892kb

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

result:

wrong answer Wrong Answer.

Subtask #3:

score: 0
Skipped

Dependency #1:

80%
Acceptable Answer

Dependency #2:

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: 4
Acceptable Answer

Test #13:

score: 4
Acceptable Answer
time: 441ms
memory: 14664kb

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

result:

points 0.80 Partially Accepted. You Got 80% score.

Subtask #8:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 2279ms
memory: 14864kb

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
8
8
8
9
6
4
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
4
9
7
7
11
8
7
8
4
7
10
6
8
6
7
7
7
7
8
7
9
11
8
7
7
7
11
8
8
7
6
4
7
8
7
8
7
6
7
8
7
11
11
6
7
7
8
8
7
4
8
8
8
9
7
7
8
6
7
7
7
11
6
7
6
8
8
8
8
7
5
6
7
4
7
7
7
8
6
8
8
5
7
8
7
6
7
8
7
6
7
11
10
8
7
8
8
6
4
11
7
7
11
7
10
7
9
7...

result:

wrong answer Wrong Answer.

Subtask #9:

score: 0
Skipped

Dependency #6:

0%

Subtask #10:

score: 0
Skipped

Dependency #5:

0%