QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337898#7769. Axium CrisisHarry27182100 ✓7156ms329804kbC++143.4kb2024-02-25 15:53:402024-02-25 15:53:40

Judging History

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

  • [2024-02-25 15:53:40]
  • 评测
  • 测评结果:100
  • 用时:7156ms
  • 内存:329804kb
  • [2024-02-25 15:53:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct edge{int v,w,id,nxt;}e[40];
struct node{int s,t,len,x,y;}a[2000005];
struct point{int x,y,val;}st[30000005];
int cnt,h[20],tot,T,tp,n,u,v,w,f[(1<<18)+5][20],val[2000005],top,dep[20],anc[20];
int p1[2000005],p2[2000005],col[20],c[20],d[20],pre[20];
void add(int u,int v,int w,int id){e[++cnt]={v,w,id,h[u]};h[u]=cnt;}
void dfs(int u,int fa,int s,int t,int len,int st)
{
	if(len)a[++tot]={s,t,len,st,u};
	for(int i=h[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==fa)continue;
		if(e[i].w==0||e[i].w==2)dfs(v,u,s,t|(1<<e[i].id),len+1,st);
		if(e[i].w==1||e[i].w==2)dfs(v,u,s|(1<<len),t|(1<<e[i].id),len+1,st);
	}
}
void dfs1(int u,int fa)
{
	dep[u]=(fa==-1?1:dep[fa]+1);anc[u]=fa;
	for(int i=h[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==fa)continue;
		pre[v]=e[i].id;dfs1(v,u);
	}
}
bool operator <(node x,node y)
{
	int p=__builtin_ctz(x.s^y.s);
	if(p<min(x.len,y.len))return ((x.s>>p)&1)<((y.s>>p)&1);
	return x.len<y.len;
}
int query(node x,node y)
{
	int p=__builtin_ctz(x.s^y.s);
	if(p<min(x.len,y.len))return p;
	return min(x.len,y.len);
}
void cmax(int &x,int y){x=(x>y?x:y);}
void cmin(int &x,int y){x=(x<y?x:y);}
void change(int i,int j,int val)
{
	if(f[i][j]==val)return;
	st[++top]={i,j,f[i][j]};f[i][j]=val;
}
void go(int x){while(top>x)f[st[top].x][st[top].y]=st[top].val,top--;}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin>>T>>tp;cout<<1<<'\n';
    for(int k=1;k<=T;k++)
    {
    	cin>>n;
    	for(int i=0;i<n;i++)h[i]=col[i]=0;cnt=0;tot=0;top=0;
    	for(int i=0;i<n-1;i++)
    	{
    		cin>>u>>v>>w;col[i]=w;
    		add(u,v,w,i);add(v,u,w,i);
		}
		for(int i=0;i<n;i++)dfs(i,-1,0,0,0,i);dfs1(0,-1);
		stable_sort(a+1,a+tot+1);
		for(int i=0;i<(1<<(n-1));i++)for(int j=0;j<n;j++)f[i][j]=!j;
		for(int i=1;i<=tot;i++)val[i]=query(a[i],a[i-1]);
		for(int i=1;i<=tot;i++)
		{
			int lcp=val[i],now=n-1;p1[i]=top;
			for(int x=i-1;x>=0;x--)
			{
				cmin(now,a[x].len);
				if(x!=i-1)cmin(now,val[x+1]);
				if(now<=lcp)break;
				for(int s=a[x].t;s<(1<<(n-1));s=a[x].t|(s+1))
				{
					if(f[s][now]>f[s][lcp])change(s,lcp,f[s][now]);
					change(s,now,0);
				}
			}
			p2[i]=top;
			for(int s=a[i].t;s<(1<<(n-1));s=a[i].t|(s+1))
			{
				int t=s^a[i].t,w=f[s][a[i].len];
				for(int j=0;j<=val[i];j++)cmax(w,f[t][j]+a[i].len-j);
				change(s,a[i].len,w);
			}
		}
		int pos=0,ans=0,s=(1<<(n-1))-1;
		for(int i=0;i<n;i++)if(f[(1<<(n-1))-1][i]>=ans)ans=f[(1<<(n-1))-1][i],pos=i;
		cout<<ans<<'\n';
		vector<int>res;
		for(int i=tot;i>=1;i--)
		{
			go(p2[i]);
			if((s|a[i].t)==s&&pos==a[i].len)
			{
				for(int j=val[i];j>=0;j--)
				{
					if(f[s^a[i].t][j]+a[i].len-j==ans)
					{
						pos=j;ans-=a[i].len-j;
						s^=a[i].t;res.emplace_back(i);
						break;
					}
				}
			}
			go(p1[i]);
			while(ans!=f[s][pos])pos++;
		}
		for(int i=0;i<res.size();i++)
		{
			int u=a[res[i]].x,v=a[res[i]].y,tot1=0,tot2=0;
			while(u!=v)
			{
				if(dep[u]>=dep[v])
				{
					c[++tot1]=pre[u];
					u=anc[u];
				}
				else 
				{
					d[++tot2]=pre[v];
					v=anc[v];
				}
			}
			reverse(d+1,d+tot2+1);
			for(int j=1;j<=tot2;j++)c[++tot1]=d[j];
			for(int j=1;j<=tot1;j++)col[c[j]]=(a[res[i]].s>>(j-1))&1;
		}
		cout<<res.size()<<'\n';
		for(int i=0;i<n-1;i++)cout<<col[i]<<' ';cout<<'\n';
		for(int i=0;i<res.size();i++)cout<<a[res[i]].x<<' '<<a[res[i]].y<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

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

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

result:

ok Accepted. Good Job!

Test #2:

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

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

result:

ok Accepted. Good Job!

Subtask #2:

score: 10
Accepted

Test #3:

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

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

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 10
Accepted
time: 20ms
memory: 13864kb

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

result:

ok Accepted. Good Job!

Test #6:

score: 10
Accepted
time: 17ms
memory: 15972kb

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

output:

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

result:

ok Accepted. Good Job!

Subtask #4:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 10
Accepted
time: 51ms
memory: 15880kb

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

result:

ok Accepted. Good Job!

Test #8:

score: 10
Accepted
time: 55ms
memory: 15884kb

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

result:

ok Accepted. Good Job!

Subtask #5:

score: 10
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 10
Accepted
time: 124ms
memory: 16264kb

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

result:

ok Accepted. Good Job!

Test #10:

score: 10
Accepted
time: 85ms
memory: 18084kb

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

result:

ok Accepted. Good Job!

Subtask #6:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 10
Accepted
time: 393ms
memory: 36392kb

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

result:

ok Accepted. Good Job!

Test #12:

score: 10
Accepted
time: 359ms
memory: 36624kb

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

output:

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

result:

ok Accepted. Good Job!

Subtask #7:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 559ms
memory: 30476kb

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

result:

ok Accepted. Good Job!

Subtask #8:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 6947ms
memory: 329804kb

input:

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

result:

ok Accepted. Good Job!

Test #16:

score: 15
Accepted
time: 7156ms
memory: 193500kb

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

result:

ok Accepted. Good Job!

Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 864ms
memory: 63184kb

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

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 863ms
memory: 58864kb

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

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: 1882ms
memory: 161376kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Test #20:

score: 10
Accepted
time: 1260ms
memory: 79396kb

input:

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