QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454977#7769. Axium CrisisNKheyuxiang100 ✓2981ms154836kbC++143.0kb2024-06-25 17:13:402024-06-25 17:13:40

Judging History

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

  • [2024-06-25 17:13:40]
  • 评测
  • 测评结果:100
  • 用时:2981ms
  • 内存:154836kb
  • [2024-06-25 17:13:40]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
int n,cnt,tot;
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],up[1<<18|1],di[10000003],cnk,a[35],b[35];
pair<int,int> od[10000003],nw[10000003],an[35];
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);
		a[i]=++u,b[i]=++v;
		E[u][v]=E[v][u]=w;
		id[u][v]=id[v][u]=i;
	}
	cnt=tot=cnk=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;
		up[i]=-1;
	}
	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--){
			while(up[j]>lcp[i]){
				if(f[j][up[j]-1]<f[j][up[j]]){
					f[j][up[j]-1]=f[j][up[j]];
					di[++tot]=-1;
					od[tot]=mp(j,up[j]);
					nw[tot]=mp(j,up[j]-1);
				}
				f[j][up[j]]=-1e9;
				up[j]--;
			}
			if((j&s)==0){
				for(int k=0;k<=lcp[i];k++){
					if(f[j+s][len]<f[j][k]+len-k){
						f[j+s][len]=f[j][k]+len-k;
						di[++tot]=i;
						od[tot]=mp(j,k);
						nw[tot]=mp(j+s,len);
					}
				}
				up[j+s]=max(up[j+s],len);
			}
		}
		if(f[s][len]<len){
			f[s][len]=len;
			di[++tot]=i;
			od[tot]=mp(0,0);
			nw[tot]=mp(s,len);
		}
		up[s]=max(up[s],len);
	}
	int ans=0,x=0,y=0;
	for(int j=1;j<lim;j++)
		for(int k=0;k<n;k++)
			if(ans<f[j][k]) ans=f[j][k],x=j,y=k;
	for(int i=tot;i>=1&&x!=0;i--){
		if(nw[i].first==x&&nw[i].second==y){
			if(di[i]!=-1){
				node pp=path[di[i]];
				for(int j=1;j<=pp.len;j++)
					E[pp.road[j]][pp.road[j-1]]=E[pp.road[j-1]][pp.road[j]]=((pp.num/(1<<(n-j)))&1);
				an[++cnk]=mp(pp.st,pp.ed);
			}
			x=od[i].first,y=od[i].second;
		}
	}
	printf("%d\n%d\n",ans+1,cnk);
	for(int i=1;i<n;i++) printf("%d ",E[a[i]][b[i]]%2);
	printf("\n");
	for(int i=1;i<=cnk;i++) printf("%d %d\n",an[i].first-1,an[i].second-1);
}
int main(){
	int t,o;
	scanf("%d%d",&t,&o);
	printf("1\n");
	while(t--) solve();
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 4ms
memory: 10180kb

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

result:

ok Accepted. Good Job!

Test #2:

score: 10
Accepted
time: 0ms
memory: 14204kb

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

result:

ok Accepted. Good Job!

Test #4:

score: 10
Accepted
time: 11ms
memory: 10100kb

input:

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

output:

1
3
1
0 0 
0 2
4
2
1 0 1 
1 2
2 3
6
2
1 0 1 1 0 
1 5
0 2
4
2
1 0 1 
0 2
2 3
4
1
1 1 0 
1 3
5
2
0 0 0 1 0 
2 3
5 1
4
1
0 1 1 
0 3
4
1
1 0 1 
2 3
4
1
0 1 0 
0 3
3
1
0 0 0 
2 3
4
1
0 0 1 
2 0
3
1
0 0 0 
1 2
4
1
1 1 0 
3 0
4
1
1 0 0 
1 2
6
1
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: 22ms
memory: 12464kb

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

result:

ok Accepted. Good Job!

Subtask #4:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 10
Accepted
time: 75ms
memory: 15368kb

input:

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

output:

1
8
2
1 0 1 0 0 1 0 
1 7
3 5
5
2
0 1 0 1 
2 3
3 4
5
1
0 0 0 1 
1 3
3
1
1 1 1 1 1 
1 5
5
2
0 0 1 1 
1 2
1 0
8
1
0 1 1 1 1 0 0 
5 4
7
2
0 0 0 1 0 0 1 
6 0
7 1
5
2
0 0 0 1 
2 1
3 0
5
2
0 0 1 1 
2 3
2 4
6
2
1 0 1 0 0 
1 5
2 4
6
2
0 1 1 1 0 
4 2
1 0
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: 75ms
memory: 21260kb

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 
3 4
2 0
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 
6 2
3 10
1 0
8 9
6
2
1 1 1 0 0 
1 5
5 3
8
2
1 0 0 1 1 1 1 
7 2
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 
3 0
6
1
0 0 1 0 1 
2 0
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: 118ms
memory: 17192kb

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

output:

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

result:

ok Accepted. Good Job!

Test #10:

score: 10
Accepted
time: 95ms
memory: 15604kb

input:

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

output:

1
6
2
0 1 0 1 1 
4 1
4 2
6
2
0 0 0 1 0 0 1 
0 2
5 7
4
1
0 0 0 0 0 0 0 
4 1
6
1
1 1 0 0 0 
1 2
3
1
1 1 1 
0 2
5
2
1 0 1 0 
1 4
3 0
6
1
0 0 0 0 0 
3 1
3
1
0 0 0 0 
1 2
6
2
1 1 1 0 0 
3 4
0 5
5
2
1 0 0 0 
0 1
4 3
5
2
0 1 0 1 0 
2 1
4 5
6
2
1 1 1 1 1 0 1 
7 4
5 2
5
2
1 0 0 0 
3 4
2 1
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: 464ms
memory: 49136kb

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

result:

ok Accepted. Good Job!

Subtask #7:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 590ms
memory: 41040kb

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:

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

result:

ok Accepted. Good Job!

Subtask #8:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 2970ms
memory: 154836kb

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
1 0 0 0 0 0 0 
7 5
2 0
8
1
0 0 0 0 0 0 0 
2 6
8
2
0 0 1 1 0 0 0 
2 6
1 4
8
1
0 0 0 0 0 0 0 
2 3
9
4
1 1 1 0 0 1 0 0 0 0 
8 0
3 6
5 2
4 1
6
2
0 0 1 0 0 0 0 
4 5
2 3
7
4
1 1 0 1 1 0 0 0 0 0 0 0 0 
8 6
13 12
7 0
3 10
6
1
0 1 0 0 0 
0 5
6
2
0 0 0 1 0 0 
2 3
1 6
10
2
0 0 1 0 1 0 0 0 0 0 
8 0
3 7
8
...

result:

ok Accepted. Good Job!

Test #15:

score: 15
Accepted
time: 2951ms
memory: 147412kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Test #16:

score: 15
Accepted
time: 2981ms
memory: 147536kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 940ms
memory: 92304kb

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

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 922ms
memory: 77880kb

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

result:

ok Accepted. Good Job!

Subtask #10:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #19:

score: 10
Accepted
time: 1418ms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