QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#247996#7769. Axium CrisisNOI_AK_ME100 ✓631ms68080kbC++234.4kb2023-11-11 16:55:402023-11-11 16:55:40

Judging History

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

  • [2023-11-11 16:55:40]
  • 评测
  • 测评结果:100
  • 用时:631ms
  • 内存:68080kb
  • [2023-11-11 16:55:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll int
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e9
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<pair<ll,ll> > vec[400040],res;
vector<ll> F[18];
pair<ll,ll> mp[262144];
pair<pair<ll,ll>,ll> st[3000030];
ll t,o,n,head[22],cnt=0,d[22],top=0;
ll rt=1,tot=1,ch[400040][2],f[18][131072],g[131072],lst;
bl ck[18][131072];
struct node{
	ll nxt,to,w,id;
}e[44];
void add(ll u,ll v,ll ww,ll idd){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	e[cnt].w=ww;
	e[cnt].id=idd;
	head[u]=cnt;
}
void dfs(ll RT,ll fa,ll u,ll &now,ll S,ll col){
	if(!now) now=++tot;
	if(fa&&(d[RT]==1||d[u]==1)){
		if(RT<u){
			vec[now].push_back(MP(S<<1,col));
			mp[S<<1]=MP(RT,u);
		}
		else{
			vec[now].push_back(MP(S<<1|1,col));
			mp[S<<1|1]=MP(RT,u);
		}
	}
	go(u){
		ll v=e[i].to;
		if(v==fa) continue;
		if(e[i].w!=1) dfs(RT,u,v,ch[now][0],S|(1<<e[i].id),col);
		if(e[i].w) dfs(RT,u,v,ch[now][1],S|(1<<e[i].id),col|(1<<e[i].id));
	}
}
il void chkmax(ll x,ll S){
	if(f[g[S]][S]==-inf||(f[g[S]][S]-g[S])<(f[x][S]-x)) g[S]=x;
}
void solve(ll x,ll dep){
	sort(vec[x].begin(),vec[x].end());
	vec[x].erase(unique(vec[x].begin(),vec[x].end()),vec[x].end());
	fr(i,0,(ll)vec[x].size()-1){
		if(i&&(vec[x][i].fir>>1)==(vec[x][i-1].fir>>1)) continue;
		ll tmp=((1<<(n-1))-1)^((1<<(lst+1))-1);
		fr(j,lst+1,n-1){
			fr(k,0,(ll)F[j].size()-1){
				ll S=F[j][k];
				if(f[lst][S]<f[j][S]){
					f[lst][S]=f[j][S];
					chkmax(lst,S);
					if(!ck[lst][S]){
						ck[lst][S]=1;
						F[lst].push_back(S);
					}
					st[++top]=MP(MP(S<<6|lst,j),0);
				}
				ck[j][S]=0;
			}
			F[j].clear();
		}
		ll u=vec[x][i].fir>>1;
		tmp=u^((1<<(n-1))-1);
		for(ll S=tmp;;S=(S-1)&tmp){
			if(f[g[S]][S]!=-inf&&f[dep][S|u]<(f[g[S]][S]+dep-g[S])){
				f[dep][S|u]=f[g[S]][S]+dep-g[S];
				st[++top]=MP(MP((S|u)<<6|dep,vec[x][i].fir<<6|g[S]),vec[x][i].sec);
				if(!ck[dep][S|u]){
					ck[dep][S|u]=1;
					F[dep].push_back(S|u);
				}
				chkmax(dep,S|u);
			}
			if(!S) break;
		}
		lst=dep;
	}
	if(ch[x][0]) solve(ch[x][0],dep+1);
	if(ch[x][1]) solve(ch[x][1],dep+1);
	lst=min(lst,dep-1);
}
il void clr(){
	fr(i,1,n) head[i]=d[i]=0;
	cnt=0;
	fr(i,1,tot){
		vec[i].clear();
		ch[i][0]=ch[i][1]=0;
	}
	rt=tot=1;
	fr(i,0,n-1) F[i].clear();
	fr(i,0,(1<<(n-1))-1) g[i]=0;
	fr(i,0,n-1) fr(j,0,(1<<(n-1))-1) ck[i][j]=0;
	res.clear();
	top=0;
}
int main(){
	t=read();
	o=read();
	writeln(1);
	while(t--){
		n=read();
		fr(i,2,n){
			ll u=read()+1,v=read()+1,w=read();
			add(u,v,w,i-2);
			add(v,u,w,i-2);
			d[u]++;
			d[v]++;
		}
		fr(i,1,n) dfs(i,0,i,rt,0,0);
		fr(i,0,n-1) fr(j,0,(1<<(n-1))-1) f[i][j]=-inf;
		f[0][0]=0;
		F[0].push_back(0);
		ck[0][0]=1;
		lst=0;
		solve(rt,0);
		ll x=0,y=0,ans=0;
		fr(i,0,n-1){
			fr(S,0,(1<<(n-1))-1){
				if(ans<f[i][S]){
					ans=f[i][S];
					x=S;
					y=i;
				}
			}
		}
		writeln(ans+1);
		ll ncol=0;
		while(top){
			if(st[top].fir.fir==(x<<6|y)){
				ll xx=st[top].fir.sec>>6,yy=st[top].fir.sec&31;
				if(xx){
					ncol|=st[top].sec;
					res.push_back(mp[xx]);
				}
				x^=(xx>>1);
				y=yy;
			}
			top--;
		}
		fr(i,0,n-2) if(e[2*i+1].w==1) ncol|=1<<i;
		writeln((ll)res.size());
		fr(i,0,n-2) writesp((ncol>>i)&1);
		enter;
		fr(i,0,(ll)res.size()-1) pf("%d %d\n",res[i].fir-1,res[i].sec-1);
		clr();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

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

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 
0 2
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 0 
0 2
4
2
1 1 0 
1 3
2 0
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 
1 2
1 0
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: 0ms
memory: 21560kb

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

ok Accepted. Good Job!

Test #4:

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

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 
1 3
4 5
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: 7ms
memory: 25984kb

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

Dependency #2:

100%
Accepted

Test #7:

score: 10
Accepted
time: 28ms
memory: 29848kb

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

result:

ok Accepted. Good Job!

Test #8:

score: 10
Accepted
time: 22ms
memory: 26804kb

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 
2 6
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 
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: 35ms
memory: 28680kb

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

result:

ok Accepted. Good Job!

Test #10:

score: 10
Accepted
time: 32ms
memory: 28568kb

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

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

result:

ok Accepted. Good Job!

Test #12:

score: 10
Accepted
time: 87ms
memory: 32848kb

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

result:

ok Accepted. Good Job!

Subtask #7:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 91ms
memory: 33192kb

input:

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

result:

ok Accepted. Good Job!

Test #15:

score: 15
Accepted
time: 631ms
memory: 66468kb

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

result:

ok Accepted. Good Job!

Test #16:

score: 15
Accepted
time: 601ms
memory: 60160kb

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

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

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 147ms
memory: 39508kb

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
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
2 5
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: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #19:

score: 10
Accepted
time: 224ms
memory: 45872kb

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