QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275544#7769. Axium Crisisgrass8cow75 1040ms144104kbC++173.4kb2023-12-04 20:20:572023-12-04 20:20:57

Judging History

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

  • [2023-12-04 20:20:57]
  • 评测
  • 测评结果:75
  • 用时:1040ms
  • 内存:144104kb
  • [2023-12-04 20:20:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
int oi[18][18],wc[18];
vector<int>g[18];
#define pb push_back
struct ed{int S,k,u,v;};
vector<ed>st[1<<20];
int rb;
bool of[20][20][1<<18];
void dfs(int x,int f,int S,int u,int k){
	if(f!=-1&&!of[min(x,rb)][max(x,rb)][u])
	of[min(x,rb)][max(x,rb)][u]=1,st[u].pb((ed){S,k,rb,x});
	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,k);
		if(wc[w]!=0)dfs(v,x,S|(1<<w),u<<1|1,k|(1<<w));
	}
}
int js[1<<21],E,le[1<<21],sv[1<<21],lc[1<<21],jt[1<<21],jl[1<<21],jr[1<<21];
void pr(int x,int d){
	if(d==n)return;
	for(ed t:st[x])
		js[++E]=t.S,jt[E]=t.k,le[E]=d,sv[E]=x,jl[E]=t.u,jr[E]=t.v;
	pr(x<<1,d+1),pr(x<<1|1,d+1);
}
const int I=1e9;
short dp[1<<17][20];
vector<int>o[20];
void ad(short &x,short 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;
}
int tx[20100000],ty[20100000],top;
short tz[20100000];int tt[20010000];
int U[20],V[20],cc;
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;i<n;i++)for(int j=0;j<n;j++)for(int s=0;s<(1<<n);s++)
	of[i][j][s]=0;
	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++)rb=i,dfs(i,-1,0,1,0);
	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);
	top=0;
	cc=0;
	for(int i=1;i<=E;i++){
		if(i>1){
			lc[i]=((sv[i]==sv[i-1])?le[i]:jb(sv[i],sv[i-1]));
			for(int j=lc[i]+1;j<=n;j++)if(!o[j].empty()){
				for(int so:o[j]){
					if(dp[so][lc[i]]<dp[so][j]){
						tx[++top]=so,ty[top]=lc[i],tz[top]=dp[so][lc[i]];
						tt[top]=i*2-1;
						if(dp[so][lc[i]]==-1)o[lc[i]].pb(so);
						dp[so][lc[i]]=dp[so][j];
					}
					tx[++top]=so,ty[top]=j,tz[top]=dp[so][j],tt[top]=i;
					tt[top]=i*2-1;
					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]]>=zd)continue;
				if(dp[js[i]|s2][le[i]]<0)o[le[i]].pb(js[i]|s2);
				tx[++top]=js[i]|s2,ty[top]=le[i],tz[top]=dp[js[i]|s2][le[i]];
				dp[js[i]|s2][le[i]]=zd;
				tt[top]=i*2;
			}
			if(!s2)break;s2=(s2-1)&S;
		}
	}
	int as=-1,ai=-1;
	short ans=-1;
	for(int s=0;s<(1<<n);s++)for(int i=0;i<=n;i++)if(ans<dp[s][i])
	ans=dp[s][i],as=s,ai=i;
	for(int i=E;i;i--){
		short fk=dp[as][ai];
		while(top&&tt[top]==i*2)dp[tx[top]][ty[top]]=tz[top],top--;
		bool fl=0;
		if(((as&js[i])==js[i])&&fk>dp[as][ai]){
			for(int o=0;o<=n;o++)if(dp[as^js[i]][o]+le[i]-o==fk){
				as^=js[i],ai=o;
				fl=1;break;
			}
		}
		if(fl){
			for(int j=0;j<n;j++)
			if((js[i]>>j)&1)wc[j]=((jt[i]>>j)&1);
			U[++cc]=jl[i],V[cc]=jr[i];
		}
		fk=dp[as][ai];
		while(top&&tt[top]==i*2-1)dp[tx[top]][ty[top]]=tz[top],top--;
		if(i==1)continue;
		if(ai<lc[i])continue;
		for(int j=lc[i];j<=n;j++)if(dp[as][j]==fk){ai=j;break;}
	}
	printf("%d\n",(int)ans+1);
	printf("%d\n",cc);
	for(int i=0;i<n;i++){
		if(wc[i]==2)wc[i]=0;
		printf("%d ",wc[i]);
	}
	puts("");
	for(int i=1;i<=cc;i++)printf("%d %d\n",U[i],V[i]);
}
int main(){
	int T,tt;
	puts("1");
	scanf("%d%d",&T,&tt);while(T--)sol();
	return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 3ms
memory: 28840kb

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:

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

result:

ok Accepted. Good Job!

Test #2:

score: 10
Accepted
time: 3ms
memory: 29676kb

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:

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

result:

ok Accepted. Good Job!

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 7ms
memory: 29564kb

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
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1 0 0 1 0 
1 3
4
2
0 1 1 
0 3
0 1
4
1
0 1 0 
2 3
4
1
0 0 1 
0 ...

result:

ok Accepted. Good Job!

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 10
Accepted
time: 21ms
memory: 30432kb

input:

3000 4
4
2 0 0
1 2 0
1 3 0
4
1 2 2
0 2 2
3 2 2
4
3 1 2
3 2 0
0 2 0
4
0 3 2
2 1 2
0 1 2
4
0 1 0
3 0 0
0 2 2
4
2 0 0
2 1 0
3 0 0
6
0 3 2
5 0 2
5 2 2
1 4 2
4 3 2
4
0 3 0
3 1 0
0 2 0
4
1 0 2
2 0 2
3 2 2
4
2 1 2
1 0 2
0 3 2
6
5 0 2
0 2 2
0 4 2
1 0 2
0 3 2
6
4 5 2
0 1 2
0 3 2
4 3 2
5 2 2
4
1 3 0
3 2 0
1 0...

output:

1
4
1
0 0 0 
0 3
4
2
0 1 0 
0 2
1 3
4
1
0 0 0 
0 1
4
1
0 0 0 
2 3
4
2
0 0 1 
0 2
1 3
4
1
0 0 0 
1 3
6
1
0 0 0 0 0 
1 2
4
1
0 0 0 
1 2
4
1
0 0 0 
1 3
4
1
0 0 0 
2 3
5
2
0 0 0 1 0 
1 5
2 4
6
1
0 0 0 0 0 
1 2
4
1
0 0 0 
0 2
6
1
0 0 0 0 0 
1 5
4
1
0 0 0 
0 3
4
1
0 0 0 
0 1
4
1
0 0 0 0 0 
0 5
4
2
0 1 0 
...

result:

ok Accepted. Good Job!

Test #6:

score: 10
Accepted
time: 15ms
memory: 30016kb

input:

3000 0
6
1 3 2
0 4 0
1 4 2
3 5 1
0 2 0
6
0 5 0
0 4 1
0 2 0
3 0 0
1 0 0
6
4 1 2
2 1 1
5 0 2
5 3 1
2 3 0
4
2 0 0
1 0 2
1 3 0
4
2 3 1
0 1 1
2 1 0
4
0 3 1
1 0 2
2 3 0
4
1 3 1
2 3 0
0 1 2
6
1 0 1
4 1 1
5 1 1
3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 0 
0 4
1 2
5
1
0 0 0 0 1 
3 5
8
1
0 1 1 0 0 1 0 
1 7
6
1
0 1 1 1 0...

result:

ok Accepted. Good Job!

Test #8:

score: 10
Accepted
time: 73ms
memory: 35976kb

input:

3000 3
6
3 1 1
1 4 0
1 0 1
1 2 0
5 1 0
6
0 3 1
2 4 1
1 5 1
1 4 0
4 0 0
6
2 5 0
1 5 1
3 4 0
4 0 0
3 2 1
8
2 5 0
6 7 0
0 3 0
6 0 1
1 4 0
7 5 1
3 4 1
11
7 6 1
3 5 1
2 7 1
7 10 0
1 7 0
8 7 0
9 7 0
4 7 0
5 7 0
0 7 1
6
5 1 1
2 4 1
3 0 1
2 0 0
5 4 0
8
3 1 1
1 6 0
0 7 0
2 7 1
4 5 1
4 3 1
0 6 1
6
0 2 0
1 2 0...

output:

1
5
2
1 0 1 0 0 
0 4
2 3
6
2
1 1 1 0 0 
2 5
4 3
6
1
0 1 0 0 1 
0 1
8
1
0 0 0 1 0 1 1 
1 2
8
4
1 1 1 0 0 0 0 0 0 1 
0 6
3 10
1 2
8 9
6
2
1 1 1 0 0 
0 3
0 1
8
2
1 0 0 1 1 1 1 
2 7
7 5
5
2
0 0 0 0 1 
3 0
1 4
6
1
1 1 0 1 0 
0 5
6
1
0 1 1 0 0 
0 3
6
1
0 0 1 0 1 
0 2
5
1
0 0 0 1 0 
5 4
6
1
1 1 0 1 0 
4 2
...

result:

ok Accepted. Good Job!

Subtask #5:

score: 10
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 10
Accepted
time: 117ms
memory: 37824kb

input:

3000 4
6
2 5 2
3 4 0
2 1 0
0 1 0
0 3 2
6
2 0 2
1 4 0
5 3 0
0 4 2
0 3 0
8
4 6 2
2 5 2
1 0 2
5 0 2
1 4 2
4 7 2
3 7 2
6
0 4 0
5 2 0
2 1 0
1 0 2
5 3 2
8
5 6 2
6 3 2
6 7 2
7 4 2
2 6 2
1 4 2
0 4 2
6
1 5 0
2 1 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0 0 1 
1 3
2 4
8
2
1 1 0 1 0 1 1 
...

result:

ok Accepted. Good Job!

Subtask #6:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 10
Accepted
time: 476ms
memory: 83268kb

input:

3000 3
8
3 5 1
4 1 0
4 6 1
5 6 0
7 5 0
3 2 1
3 0 1
8
1 4 1
0 3 0
7 3 1
5 2 1
5 3 1
5 1 0
6 0 1
8
1 4 1
1 2 1
0 1 0
6 7 1
3 5 1
6 4 0
4 5 0
8
7 0 0
1 4 0
3 1 1
4 2 1
2 6 0
4 5 0
7 3 1
8
7 0 0
5 7 1
4 2 0
1 3 0
2 5 0
6 0 0
3 0 1
8
1 3 0
3 4 0
6 3 1
7 5 1
3 0 0
7 3 0
5 2 0
5
1 3 0
3 0 1
1 2 1
2 4 0
8
5...

output:

1
7
2
1 0 1 0 0 1 1 
2 5
7 1
7
2
1 0 1 1 1 0 1 
4 7
3 6
7
2
1 1 0 1 1 0 0 
3 2
4 7
8
2
0 0 1 1 0 0 1 
4 6
5 0
8
2
0 1 0 0 0 0 1 
0 1
4 6
7
2
0 0 1 1 0 0 0 
6 1
4 2
5
1
0 1 1 0 
4 0
7
3
1 0 1 1 1 0 0 
0 1
3 2
4 7
4
1
0 1 0 
0 2
7
2
1 1 1 0 0 1 1 
0 4
6 3
7
2
0 1 1 0 1 1 
3 6
1 5
5
2
0 0 1 0 0 0 0 
2 ...

result:

ok Accepted. Good Job!

Test #12:

score: 10
Accepted
time: 479ms
memory: 83544kb

input:

3000 3
8
4 5 1
6 4 0
3 7 1
1 6 1
0 2 1
5 7 0
1 2 0
8
6 1 1
1 4 0
6 7 0
6 0 1
2 1 1
6 3 0
5 0 1
8
1 0 0
7 3 0
1 4 0
2 1 0
6 5 0
3 4 1
5 2 1
8
0 4 1
5 2 1
3 0 0
7 0 1
0 2 0
0 1 1
6 3 1
7
3 6 1
1 0 0
0 4 1
5 2 1
5 4 0
5 6 0
8
0 1 1
7 4 0
1 2 1
0 6 0
4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

result:

ok Accepted. Good Job!

Subtask #8:

score: 0
Runtime Error

Test #14:

score: 0
Runtime Error

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:

1
7
2
0 0 0 1 0 0 0 
5 7
0 2
8
1
0 0 0 0 0 0 0 
2 6
8
2
0 0 0 1 0 0 0 
2 6
1 4
8
1
0 0 0 0 0 0 0 
2 3
9
4
0 1 1 0 0 0 0 1 0 1 
0 8
1 6
2 5
3 4
6
2
0 0 0 1 0 0 0 
3 5
2 4
7
4
1 0 1 0 1 0 0 1 0 0 0 0 0 
0 6
3 8
7 12
10 13
6
1
0 0 0 0 0 
0 5
6
2
0 0 0 0 1 0 
1 3
2 6
10
2
0 0 1 0 0 0 0 0 0 0 
0 8
3 7
8
...

result:


Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 1007ms
memory: 144104kb

input:

3000 3
8
1 2 0
4 6 1
2 4 1
3 4 1
4 0 0
5 6 0
4 7 1
8
6 0 0
2 6 1
5 4 1
0 4 1
2 3 0
7 1 1
5 1 0
17
8 7 0
15 7 0
5 7 1
4 5 1
2 5 1
16 5 1
10 16 0
14 5 1
6 2 0
3 5 1
12 7 0
14 0 0
3 1 0
9 5 1
13 5 1
16 11 0
14
4 3 0
2 10 1
12 1 0
9 7 0
6 13 0
5 11 0
8 12 1
6 3 1
4 1 1
0 10 0
2 8 0
7 5 1
0 11 1
8
7 6 0
...

output:

1
7
2
0 1 1 1 0 0 1 
3 0
1 5
8
1
0 1 1 1 0 1 0 
3 7
10
4
0 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 
4 8
5 6
0 10
12 15
14
1
0 1 0 0 0 0 1 1 1 0 0 1 1 
9 13
7
2
0 0 1 0 0 1 0 
7 4
2 1
7
2
1 1 1 1 1 1 0 
3 7
6 0
8
2
1 1 1 0 1 1 0 
2 0
3 5
7
3
1 1 1 0 0 1 1 
0 5
1 2
7 6
8
4
1 0 1 0 0 1 0 0 0 1 
0 6
3 9
4 2
7 10
...

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 1040ms
memory: 141128kb

input:

3000 3
8
2 7 0
3 4 0
1 0 0
7 5 1
2 3 1
6 5 0
0 4 1
11
10 5 1
2 5 1
5 9 0
5 0 0
4 1 0
3 5 0
5 1 1
6 5 0
7 5 0
8 1 1
8
3 4 1
1 3 1
7 3 0
5 3 0
5 2 0
6 0 0
0 2 1
7
2 5 1
1 3 1
1 5 0
0 6 1
0 2 0
6 4 0
7
0 3 0
2 6 1
0 4 1
5 1 1
4 6 0
1 3 1
11
1 4 0
9 4 0
10 4 1
4 2 0
7 4 0
7 6 1
4 5 0
8 4 1
4 0 0
4 3 1
6...

output:

1
8
1
0 0 0 1 1 0 1 
1 6
8
4
1 1 0 0 0 0 1 0 0 1 
8 9
2 0
3 10
6 7
8
2
1 1 0 0 0 0 1 
1 7
6 4
7
1
1 1 0 1 0 0 
4 3
7
2
0 1 1 1 0 1 
2 6
6 5
8
4
0 0 1 0 0 1 0 1 0 1 
3 10
6 1
2 8
5 9
6
2
0 1 1 1 0 
0 2
4 5
7
2
1 0 0 0 0 0 1 
4 1
0 5
11
1
0 1 0 1 0 1 1 0 0 1 
0 5
7
3
1 0 0 0 1 0 0 
6 4
0 1
3 5
7
2
1 1...

result:

ok Accepted. Good Job!

Subtask #10:

score: 0
Skipped

Dependency #5:

100%
Accepted

Dependency #8:

0%