QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411997#8359. travelzhouhuanyi51 1063ms208560kbC++148.9kb2024-05-15 22:49:512024-05-15 22:49:52

Judging History

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

  • [2024-05-15 22:49:52]
  • 评测
  • 测评结果:51
  • 用时:1063ms
  • 内存:208560kb
  • [2024-05-15 22:49:51]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
#include<cassert>
#include<cstdlib>
#include<random>
#define N 1000000
using namespace std;
mt19937 RAND(random_device{}());
const int inf=(int)(1e9);
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int num,data;
	bool operator < (const reads &t)const
	{
		return num<t.num;
	}
};
reads tong[N+1],tongs[N+1];
int T,n,op,rt,rst,leng,lengw,lengst,nws,length,lengths,lg[N+1],depth[N+1],sdepth[N+1],sfa[N+1][21],ls[N+1],rs[N+1],ans[N+1],tans[N+1],pst,dque[N+1],top,fa[N+1],sz[N+1],cnt[N+1],dp[N+1],cl[N+1],maxp[N+1];
long long k,sk,res;
bool used[N+1];
vector<int>E[N+1];
vector<int>p[N+1];
vector<int>v[N+1];
set<int>s;
void add(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
int lca(int x,int y)
{
	if (sdepth[x]<sdepth[y]) swap(x,y);
	for (int i=lg[n];i>=0;--i)
		if (sdepth[sfa[x][i]]>=sdepth[y])
			x=sfa[x][i];
	if (x==y) return x;
	for (int i=lg[n];i>=0;--i)
		if (sfa[x][i]!=sfa[y][i])
			x=sfa[x][i],y=sfa[y][i];
	return sfa[x][0];
}
int dis(int x,int y)
{
	return sdepth[x]+sdepth[y]-(sdepth[lca(x,y)]<<1);
}
void dfs(int x)
{
	used[x]=sz[x]=1,maxp[x]=0;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			sdepth[E[x][i]]=sdepth[x]+1,sfa[E[x][i]][0]=x,dfs(E[x][i]),sz[x]+=sz[E[x][i]],maxp[x]=max(maxp[x],sz[E[x][i]]);
	maxp[x]=max(maxp[x],n-sz[x]);
	if (maxp[x]<maxp[rt]) rt=x;
	return;
}
void dfs2(int x)
{
	used[x]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
		{
			if (x==rt) cl[E[x][i]]=++lengw;
			else cl[E[x][i]]=cl[x];
			fa[E[x][i]]=x,depth[E[x][i]]=depth[x]+1,dfs2(E[x][i]);
		}
	return;
}
int smerge(int x,int y)
{
	++nws,ls[nws]=x,rs[nws]=y;
	return nws;
}
void merge(int x,int y)
{
	if (v[x].size()>v[y].size()) swap(v[x],v[y]);
	for (int i=0;i<v[x].size();++i) v[y].push_back(v[x][i]);
	v[x].clear(),v[x].shrink_to_fit();
	return;
}
void dfs3(int x)
{
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			dfs3(E[x][i]),dp[x]+=dp[E[x][i]];
	cnt[x]+=dp[x];
	return;
}
void dfs4(int x)
{
	int scnt=1,d,ds=x,pv=-1;
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			dfs4(E[x][i]),scnt+=cnt[E[x][i]];
    scnt-=cnt[x],s.clear();
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			s.insert(E[x][i]);
	for (int i=1;i<=scnt;++i)
	{
		auto it=s.begin();
		if ((*it)!=pv) d=(*it);
		else
		{
			it++;
			if (it==s.end()) it--,d=(*it);
			else d=(*it);
		}
		if (d!=pv) ds=smerge(ds,v[d].back()),v[d].pop_back();
		else ds=smerge(v[d].back(),ds),v[d].pop_back();
		if (v[d].empty()) s.erase(d);
		pv=d;
	}
	v[x].push_back(ds);
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			merge(E[x][i],x);
	return;
}
void dfs5(int x)
{
	if (x<=n) ans[++pst]=x;
	else dfs5(ls[x]),dfs5(rs[x]);
	return;
}
void adder(int x,int d)
{
	top=0;
	while (x!=rt) dque[++top]=x,x=fa[x];
	for (int i=1;i<=d;++i) cnt[dque[i]]++;
	return;
}
int get_maxn()
{
	int x=1,y=1,maxn=0;
	for (int i=1;i<=n;++i)
		if (dis(x,i)>maxn)
			y=i,maxn=dis(x,y);
	for (int i=1;i<=n;++i)
		if (dis(y,i)>maxn)
			x=i,maxn=dis(x,y);
	rst=x;
	return maxn;
}
bool dst[N+1];
bool cmp(int x,int y)
{
	return dst[x]<dst[y];
}
void dfs6(int x)
{
	used[x]=1,dst[x]=(x==rst);
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			dfs6(E[x][i]),dst[x]|=dst[E[x][i]];
	return;
}
void dfs7(int x)
{
	ans[++leng]=x,used[x]=1,sort(E[x].begin(),E[x].end(),cmp);
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			dfs7(E[x][i]);
	return;
}
int main()
{
	int x,y,wst,sl;
	long long sk;
	for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
	T=read(),maxp[0]=inf;
	for (int qt=1;qt<=T;++qt)
	{
		n=read(),sk=k=read(),op=read();
		for (int i=1;i<=n;++i) E[i].clear(),used[i]=0;
		for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
		if (op==1)
		{
			rt=rst=leng=res=lengw=length=lengths=pst=0,nws=n;
			for (int i=1;i<=n;++i) sfa[i][0]=0;
			sdepth[1]=1,dfs(1);
			for (int i=1;i<=lg[n];++i)
				for (int j=1;j<=n;++j)
					sfa[j][i]=sfa[sfa[j][i-1]][i-1];
			for (int i=1;i<=n;++i) used[i]=fa[i]=cnt[i]=dp[i]=ls[i]=rs[i]=0,v[i].clear();
			depth[rt]=0,dfs2(rt);
			for (int i=1;i<=leng;++i) p[i].clear();
			for (int i=1;i<=n;++i) res+=(depth[i]<<1);
			if (k<((n-1)<<1)-get_maxn()||k>res-1)
			{
				puts("-1");
				continue;
			}
			if (k<((n-1)<<1))
			{
				k=((n-1)<<1)-k;
				for (int i=1;i<=n;++i)
					if (dis(rst,i)==k)
					{
						for (int j=1;j<=n;++j) used[j]=0;
						dfs6(i);
						for (int j=1;j<=n;++j) used[j]=0;
						dfs7(i);
						break;
					}
			}
			else
			{
				int rcnt=0,wcnt=0;
				if (n<=20) wcnt=10;
				else wcnt=2;
				sl=0;
				while (1)
				{
					for (int i=1;i<=n;++i) shuffle(E[i].begin(),E[i].end(),RAND);
					wst=RAND()%min(min((long long)(n-1),res-sk)+1,10ll),k=sk+wst,leng=length=lengths=pst=0;
					if (k&1) continue;
					rcnt++;
					if (rcnt>wcnt)
					{
						for (int i=1;i<=n;++i) ans[i]=i;
						break;
					}
					k=(k>>1)-(n-1);
					for (int i=1;i<=n;++i) used[i]=cnt[i]=dp[i]=ls[i]=rs[i]=0,v[i].clear();
					for (int i=1;i<=n;++i)
						if (i!=rt)
							cnt[i]=1;
					for (int i=1;i<=n;++i)
						if (i!=rt)
						{
							for (int j=1;j<=E[i].size()-1;++j) tong[++length]=(reads){cl[i],i};
						}
					sort(tong+1,tong+length+1);
					if (length&1) tongs[++lengths]=tong[(length+1)>>1];
					for (int i=1;i<=(length>>1);++i)
					{
						if (tong[i].num!=tongs[lengths].num) tongs[++lengths]=tong[i],tongs[++lengths]=tong[i+((length+1)>>1)];
						else tongs[++lengths]=tong[i+((length+1)>>1)],tongs[++lengths]=tong[i];
					}
					for (int i=1;i<=lengths;++i)
					{
						if (k>=depth[tongs[i].data]) dp[tongs[i].data]++,k-=depth[tongs[i].data];
						else if (k)
						{
							adder(tongs[i].data,k),k=0;
							break;
						}
					}
					dfs3(rt),length=lengths=0;
					for (int i=0;i<E[rt].size();++i)
					{
						dfs4(E[rt][i]);
						for (int j=0;j<v[E[rt][i]].size();++j) tong[++length]=(reads){i+1,v[E[rt][i]][j]};
					}
					sort(tong+1,tong+length+1);
					if (length&1) tongs[++lengths]=tong[(length+1)>>1];
					for (int i=1;i<=(length>>1);++i)
					{
						if (tong[i].num!=tongs[lengths].num) tongs[++lengths]=tong[i],tongs[++lengths]=tong[i+((length+1)>>1)];
						else tongs[++lengths]=tong[i+((length+1)>>1)],tongs[++lengths]=tong[i];
					}
					tongs[++lengths]=(reads){0,rt};
					for (int i=1;i<=lengths;++i) dfs5(tongs[i].data);
					bool opst=0;
					for (int i=1;i<=n;++i)
						if (dis(ans[i],ans[i%n+1])==wst)
						{
							opst=1,sl=i;
							break;
						}
					if (opst) break;
				}
				lengst=0;
				for (int i=sl;i>=1;--i) tans[++lengst]=ans[i];
				for (int i=n;i>=sl+1;--i) tans[++lengst]=ans[i];
				reverse(tans+1,tans+lengst+1);
				for (int i=1;i<=n;++i) ans[i]=tans[i];
			}
			for (int i=1;i<=n;++i) printf("%d ",ans[i]);
			puts("");
		}
		else
		{
			rt=leng=res=length=lengths=lengw=pst=0,nws=n;
			for (int i=1;i<=n;++i) sfa[i][0]=0;
			sdepth[1]=1,dfs(1);
			for (int i=1;i<=lg[n];++i)
				for (int j=1;j<=n;++j)
					sfa[j][i]=sfa[sfa[j][i-1]][i-1];
			for (int i=1;i<=n;++i) used[i]=fa[i]=cnt[i]=dp[i]=ls[i]=rs[i]=0,v[i].clear();
			depth[rt]=0,dfs2(rt);
			for (int i=1;i<=leng;++i) p[i].clear();
			for (int i=1;i<=n;++i) res+=(depth[i]<<1);
			if (k<((n-1)<<1)||k>res||(k&1))
			{
				puts("-1");
				continue;
			}
			k=(k>>1)-(n-1);
			for (int i=1;i<=n;++i)
				if (i!=rt)
					cnt[i]=1;
			for (int i=1;i<=n;++i)
				if (i!=rt)
				{
					for (int j=1;j<=E[i].size()-1;++j) tong[++length]=(reads){cl[i],i};
				}
			sort(tong+1,tong+length+1);
			if (length&1) tongs[++lengths]=tong[(length+1)>>1];
			for (int i=1;i<=(length>>1);++i)
			{
				if (tong[i].num!=tongs[lengths].num) tongs[++lengths]=tong[i],tongs[++lengths]=tong[i+((length+1)>>1)];
				else tongs[++lengths]=tong[i+((length+1)>>1)],tongs[++lengths]=tong[i];
			}
			for (int i=1;i<=lengths;++i)
			{
				if (k>=depth[tongs[i].data]) dp[tongs[i].data]++,k-=depth[tongs[i].data];
				else if (k)
				{
					adder(tongs[i].data,k),k=0;
					break;
				}
			}
			dfs3(rt),length=lengths=0;
			for (int i=0;i<E[rt].size();++i)
			{
				dfs4(E[rt][i]);
				for (int j=0;j<v[E[rt][i]].size();++j) tong[++length]=(reads){i+1,v[E[rt][i]][j]};
			}
			sort(tong+1,tong+length+1);
			if (length&1) tongs[++lengths]=tong[(length+1)>>1];
			for (int i=1;i<=(length>>1);++i)
			{
				if (tong[i].num!=tongs[lengths].num) tongs[++lengths]=tong[i],tongs[++lengths]=tong[i+((length+1)>>1)];
				else tongs[++lengths]=tong[i+((length+1)>>1)],tongs[++lengths]=tong[i];
			}
			tongs[++lengths]=(reads){0,rt};
			for (int i=1;i<=lengths;++i) dfs5(tongs[i].data);
			for (int i=1;i<=n;++i) printf("%d ",ans[i]);
			puts("");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 15ms
memory: 77692kb

input:

0

output:


result:

ok Accepted.

Subtask #2:

score: 2
Acceptable Answer

Test #2:

score: 4
Accepted
time: 11ms
memory: 77996kb

input:

5
9 28 2
8 6
6 3
3 2
9 5
4 1
1 5
5 2
2 7
9 16 2
1 3
7 8
4 2
2 9
9 8
8 6
6 3
3 5
9 12 1
7 5
5 9
9 2
2 8
6 1
1 8
8 4
4 3
9 22 1
8 5
2 4
4 1
1 6
6 9
7 9
9 5
5 3
9 27 1
2 6
4 8
8 1
5 9
9 1
1 7
7 6
6 3

output:

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

result:

ok Accepted.

Test #3:

score: 4
Accepted
time: 8ms
memory: 77988kb

input:

5
9 16 2
4 3
3 1
7 6
2 8
8 6
6 1
1 5
9 5
9 12 1
6 7
5 4
4 1
1 3
3 2
2 7
8 7
7 9
9 14 1
1 2
2 3
6 4
8 9
9 3
3 4
5 4
4 7
9 12 1
9 4
4 1
1 5
3 2
2 6
6 5
8 5
5 7
9 9 1
8 7
7 3
3 2
2 9
4 9
9 1
1 6
6 5

output:

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

result:

ok Accepted.

Test #4:

score: 4
Accepted
time: 16ms
memory: 78192kb

input:

5
9 13 1
4 7
7 8
8 5
1 9
2 5
3 5
5 9
9 6
9 16 2
7 3
1 5
5 8
8 9
2 3
4 9
9 3
3 6
9 26 1
1 3
3 8
8 9
7 4
2 6
6 9
9 4
4 5
9 25 1
5 3
7 2
2 4
4 9
6 1
1 9
9 3
3 8
9 14 1
3 8
8 5
5 4
7 6
6 4
4 2
2 9
9 1

output:

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

result:

ok Accepted.

Test #5:

score: 4
Accepted
time: 7ms
memory: 77980kb

input:

5
9 27 1
8 2
6 9
9 1
4 5
5 1
1 2
2 7
7 3
9 16 2
2 6
6 9
7 8
8 4
1 4
5 4
4 9
9 3
9 30 1
6 7
9 4
4 2
2 5
1 5
5 3
3 7
7 8
9 12 1
4 1
8 6
6 3
2 5
5 1
1 3
3 7
7 9
9 22 1
2 3
7 8
8 1
1 9
9 5
5 3
3 4
6 4

output:

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

result:

ok Accepted.

Test #6:

score: 4
Accepted
time: 12ms
memory: 77984kb

input:

5
9 18 2
7 3
3 8
8 4
4 9
9 1
1 5
2 6
5 6
9 26 2
8 3
3 9
9 5
4 2
2 5
6 7
7 5
5 1
9 25 1
1 5
5 9
9 6
2 4
7 6
6 8
8 4
4 3
9 26 2
1 9
9 4
4 6
5 7
3 7
7 6
6 2
2 8
9 26 2
1 4
4 6
6 8
3 9
9 2
5 8
8 7
7 2

output:

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

result:

ok Accepted.

Test #7:

score: 4
Accepted
time: 11ms
memory: 77976kb

input:

5
9 13 1
2 4
5 8
8 1
6 9
9 7
7 1
1 4
4 3
9 29 2
3 2
1 8
8 4
4 6
6 7
5 2
2 9
9 7
9 15 2
1 3
3 7
7 2
2 9
4 5
5 9
9 6
6 8
9 31 1
2 9
9 8
8 6
6 5
5 4
7 4
4 1
1 3
9 21 2
7 2
2 5
1 4
3 6
6 5
9 4
4 5
5 8

output:

7 9 6 1 8 5 4 3 2 
-1
-1
6 5 9 4 3 2 1 8 7 
-1

result:

ok Accepted.

Test #8:

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

input:

5
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2

output:

-1
1 
1 
-1
1 

result:

points 0.50 Partially Correct | type = 2

Subtask #3:

score: 4
Acceptable Answer

Dependency #2:

50%
Acceptable Answer

Test #9:

score: 8
Accepted
time: 16ms
memory: 77996kb

input:

5
13 37 1
3 12
12 7
4 13
13 11
11 8
8 6
1 2
10 9
9 7
7 5
5 6
6 2
13 42 1
2 4
4 13
13 5
5 7
7 12
8 6
6 9
1 10
10 11
3 9
9 12
12 11
13 15 1
9 2
2 11
12 4
4 5
5 6
6 3
3 11
8 13
13 1
7 11
11 10
10 1
13 48 1
11 3
3 4
12 1
7 5
5 8
8 2
2 1
10 1
1 4
4 6
13 9
9 6
13 68 2
13 4
6 5
2 1
1 9
9 11
11 12
12 7
7 5
...

output:

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

result:

ok Accepted.

Test #10:

score: 8
Accepted
time: 11ms
memory: 78292kb

input:

5
13 34 2
2 7
5 11
13 1
1 3
8 9
9 6
6 11
11 3
3 7
7 12
12 4
4 10
13 17 1
2 7
7 11
11 9
10 12
12 4
6 13
13 4
4 8
8 3
3 1
1 9
9 5
13 33 1
7 6
6 1
1 10
10 13
9 4
11 12
12 13
8 13
2 4
4 13
13 3
5 3
13 17 1
8 11
11 13
13 3
3 5
10 2
2 1
1 6
12 7
6 5
5 4
4 9
9 7
13 15 1
5 1
8 3
2 13
13 11
11 6
6 7
7 9
9 1
...

output:

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

result:

ok Accepted.

Test #11:

score: 8
Accepted
time: 8ms
memory: 78016kb

input:

5
13 24 2
1 5
11 12
12 2
2 10
4 9
9 3
6 13
13 8
8 5
5 10
10 3
3 7
13 28 2
13 5
5 7
7 3
9 6
4 10
8 12
1 12
12 6
6 3
3 2
2 10
10 11
13 50 2
4 13
13 8
8 10
10 1
3 5
12 7
7 1
1 9
9 5
5 2
6 2
11 2
13 64 2
10 3
3 9
9 7
7 11
11 5
5 13
6 2
2 8
4 8
1 13
13 8
8 12
13 52 2
13 12
12 8
8 10
5 6
6 11
9 2
7 2
1 10...

output:

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

result:

ok Accepted.

Test #12:

score: 8
Accepted
time: 11ms
memory: 78016kb

input:

5
13 34 1
8 11
11 2
2 10
9 6
3 1
4 13
13 7
7 6
6 12
12 1
1 10
10 5
13 31 1
11 1
1 9
9 5
6 7
7 2
13 4
4 2
2 10
10 12
12 8
8 5
5 3
13 28 2
2 8
8 9
9 6
6 7
4 13
13 11
11 7
7 5
5 1
12 1
1 3
3 10
13 49 1
11 4
4 1
1 8
8 12
12 3
3 7
6 2
13 7
7 5
2 10
10 9
9 5
13 62 1
12 9
9 5
5 6
6 1
1 4
4 2
2 3
8 11
7 10
...

output:

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

result:

ok Accepted.

Test #13:

score: 8
Accepted
time: 11ms
memory: 77968kb

input:

5
13 59 1
10 9
3 8
8 7
7 6
6 12
4 1
13 5
5 12
12 2
2 9
9 1
1 11
13 30 2
9 5
2 1
1 3
3 12
12 8
8 7
7 6
11 10
10 5
5 6
4 6
13 6
13 54 1
11 13
13 12
12 10
9 3
3 5
4 2
6 10
10 7
7 5
5 2
1 2
2 8
13 24 2
2 11
5 12
12 4
8 3
3 6
6 7
7 1
10 9
9 4
4 1
1 11
11 13
13 56 2
3 2
2 8
4 9
9 1
1 5
7 10
10 5
5 11
11 8...

output:

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

result:

ok Accepted.

Test #14:

score: 8
Accepted
time: 12ms
memory: 77976kb

input:

5
13 21 2
1 11
11 10
12 6
6 8
8 2
2 4
4 7
9 5
5 3
13 10
10 3
3 7
13 34 1
11 4
4 12
2 13
13 8
8 5
10 6
7 1
3 6
6 12
12 9
1 5
5 9
13 137 2
7 9
13 12
12 4
4 5
5 10
10 11
11 9
9 8
2 1
8 3
3 1
6 1
13 13 1
13 12
12 2
2 8
8 9
9 3
3 10
1 10
10 6
7 5
5 6
6 11
11 4
13 25 2
6 9
4 12
12 5
5 1
1 3
7 13
13 9
9 8
...

output:

-1
12 11 10 8 13 2 4 1 6 3 9 5 7 
-1
-1
-1

result:

ok Accepted.

Test #15:

score: 4
Acceptable Answer
time: 15ms
memory: 77988kb

input:

5
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2

output:

-1
1 
1 
-1
1 

result:

points 0.50 Partially Correct | type = 2

Subtask #4:

score: 7
Acceptable Answer

Test #16:

score: 7
Acceptable Answer
time: 8ms
memory: 78040kb

input:

200
9 38 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 26 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
10 30 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
9 30 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
10 28 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 41 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 44 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10...

output:

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

result:

points 0.50 Partially Correct | type = 2

Test #17:

score: 14
Accepted
time: 18ms
memory: 78200kb

input:

200
9 8 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 17 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 8 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
10 45 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
9 29 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
10 51 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
9 39 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 16 2
1 2
2 ...

output:

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

result:

ok Accepted.

Test #18:

score: 7
Acceptable Answer
time: 16ms
memory: 77972kb

input:

2000
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 1
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 1
1...

output:

1 
-1
-1
1 
1 
-1
1 
-1
-1
1 
-1
-1
-1
1 
1 
-1
1 
1 
-1
-1
1 
-1
1 
1 
-1
1 
1 
-1
1 
-1
-1
-1
-1
1 
1 
1 
-1
-1
-1
1 
1 
-1
1 
1 
-1
-1
1 
1 
-1
1 
1 
1 
1 
1 
1 
1 
-1
-1
1 
-1
1 
1 
-1
1 
-1
1 
1 
1 
-1
-1
1 
-1
1 
-1
1 
1 
1 
1 
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
1 
-1
-1
1 
-1
-1
-1
-1
1 
1 
1 
...

result:

points 0.50 Partially Correct | type = 2

Test #19:

score: 7
Acceptable Answer
time: 12ms
memory: 78004kb

input:

50
37 420 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 57 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17...

output:

2 36 1 37 18 35 17 34 16 33 15 32 14 31 13 30 12 20 21 22 29 23 24 25 26 27 28 11 10 9 8 7 6 5 4 3 19 
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 
22 23 24 25 26 27 28 29 30 31 32 33 34 35 20 21 8 6 4 2 1 39 7 5 3 40 16 15 14 13 12 11 10 9 3...

result:

points 0.50 Partially Correct | type = 2

Test #20:

score: 7
Acceptable Answer
time: 4ms
memory: 78024kb

input:

20
90 206 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52...

output:

29 27 25 23 21 19 17 15 30 28 26 24 22 20 18 16 14 13 12 11 10 9 8 7 6 5 4 3 2 1 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 
48 47 46 45 44 43 42 41 40 39 38 37 50...

result:

points 0.50 Partially Correct | type = 2

Test #21:

score: 7
Acceptable Answer
time: 4ms
memory: 78088kb

input:

5
384 396 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52...

output:

371 372 373 374 375 376 377 378 379 380 381 382 383 384 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311 310 ...

result:

points 0.50 Partially Correct | type = 2

Test #22:

score: 14
Accepted
time: 4ms
memory: 78300kb

input:

5
378 26744 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 ...

output:

121 302 139 303 169 304 168 305 167 306 166 307 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 308 142 309 141 310 140 311 170 312 138 313 137 314 136 315 135 316 134 317 133 318 132 293 131 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 ...

result:

ok Accepted.

Test #23:

score: 7
Acceptable Answer
time: 15ms
memory: 78444kb

input:

1
1934 290581 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
5...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

points 0.50 Partially Correct | type = 2

Test #24:

score: 14
Accepted
time: 9ms
memory: 78504kb

input:

1
1919 3856 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 ...

output:

959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 899 898 897 896 895 894 893 892 891 890 889 888 887 886 885 ...

result:

ok Accepted.

Test #25:

score: 14
Accepted
time: 11ms
memory: 78448kb

input:

1
1835 1628390 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
...

output:

914 921 915 920 916 919 917 1834 877 958 864 971 865 970 866 969 867 968 868 967 869 966 870 965 871 964 872 963 873 962 874 961 875 960 876 959 807 1028 878 957 879 956 880 955 881 954 882 953 883 952 884 951 885 950 886 949 887 948 888 947 889 946 738 1097 725 1110 726 1109 727 1108 728 1107 729 1...

result:

ok Accepted.

Test #26:

score: 14
Accepted
time: 8ms
memory: 78672kb

input:

1
1854 642226 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
5...

output:

580 1501 690 1502 814 1503 813 1504 812 1505 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748...

result:

ok Accepted.

Subtask #5:

score: 5
Acceptable Answer

Dependency #4:

50%
Acceptable Answer

Test #27:

score: 5
Acceptable Answer
time: 46ms
memory: 78188kb

input:

500000
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2...

output:

-1
1 
1 
-1
1 
1 
1 
1 
1 
1 
1 
1 
-1
-1
-1
-1
1 
1 
1 
-1
1 
1 
-1
-1
1 
-1
1 
1 
1 
-1
-1
1 
1 
1 
1 
1 
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
-1
1 
1 
-1
-1
1 
1 
1 
1 
1 
-1
1 
1 
-1
1 
-1
1 
1 
1 
1 
1 
-1
-1
1 
-1
1 
-1
-1
1 
1 
-1
-1
1 
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
1 
-1
-1
1 
1 
1 
1 
1 
...

result:

points 0.50 Partially Correct | type = 2

Test #28:

score: 5
Acceptable Answer
time: 190ms
memory: 104300kb

input:

5
93044 1765038246 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

29585 76102 37289 76103 37298 76104 37297 76105 37296 76106 37295 76107 37294 76108 37293 76109 37292 76110 37291 76111 37290 76112 37299 76113 37288 76114 37287 76115 37286 76116 37285 76117 37284 76118 37283 76119 37282 76092 37281 76083 37308 76084 37317 76085 37316 76086 37315 76087 37314 76088 ...

result:

points 0.50 Partially Correct | type = 2

Test #29:

score: 10
Accepted
time: 181ms
memory: 202996kb

input:

1
481849 965190 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51...

output:

240924 240923 240922 240921 240920 240919 240918 240917 240916 240915 240914 240913 240912 240911 240910 240909 240908 240907 240906 240905 240904 240903 240902 240901 240900 240899 240898 240897 240896 240895 240894 240893 240892 240891 240890 240889 240888 240887 240886 240885 240884 240883 240882...

result:

ok Accepted.

Test #30:

score: 10
Accepted
time: 176ms
memory: 205904kb

input:

1
494761 38887392602 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
...

output:

149892 397265 176088 397266 176097 397267 176096 397268 176095 397269 176094 397270 176093 397271 176092 397272 176091 397273 176090 397274 176089 397275 176098 397276 176087 397277 176086 397278 176085 397279 176084 397280 176083 397281 176082 397282 176081 397283 176080 397255 176079 397246 176107...

result:

ok Accepted.

Test #31:

score: 5
Acceptable Answer
time: 442ms
memory: 208560kb

input:

1
490645 44453587331 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

points 0.50 Partially Correct | type = 2

Test #32:

score: 10
Accepted
time: 304ms
memory: 196740kb

input:

1
456012 71620971179 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
...

output:

228009 228005 228008 228006 456011 227979 228034 227970 228043 227971 228042 227972 228041 227973 228040 227974 228039 227975 228038 227976 228037 227977 228036 227978 228035 227930 228083 227980 228033 227981 228032 227982 228031 227983 228030 227984 228029 227985 228028 227986 228027 227987 228026...

result:

ok Accepted.

Test #33:

score: 5
Acceptable Answer
time: 67ms
memory: 77964kb

input:

5000
98 194 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 ...

output:

49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 50 
-1
-1
-1
1 2 3...

result:

points 0.50 Partially Correct | type = 2

Test #34:

score: 5
Acceptable Answer
time: 123ms
memory: 78020kb

input:

20000
23 84 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
24 216 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
23 154 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
...

output:

3 14 16 18 20 22 10 2 1 8 7 6 5 4 12 13 15 17 19 21 23 11 9 
2 21 1 22 23 24 12 20 11 19 10 18 9 17 8 16 7 15 6 14 5 4 3 13 
3 22 2 1 23 4 21 11 5 10 9 8 7 6 13 14 15 16 17 18 19 20 12 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
11 10 23 9 22 8 21 7 20 6 19 5 18 4 14 15 16 17 2 ...

result:

points 0.50 Partially Correct | type = 2

Test #35:

score: 5
Acceptable Answer
time: 143ms
memory: 78068kb

input:

2000
231 5063 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
5...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

points 0.50 Partially Correct | type = 2

Test #36:

score: 5
Acceptable Answer
time: 152ms
memory: 78920kb

input:

200
2422 1517004 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 5...

output:

793 2011 1007 2010 998 2009 999 2008 1000 2007 1001 2006 1002 2005 1003 2004 1004 2003 1005 2002 1006 2001 997 2000 1008 1999 1009 1998 1010 1997 1011 1996 1012 1995 1013 1994 1014 1993 1015 2022 1016 2031 987 2030 978 2029 979 2028 980 2027 981 2026 982 2025 983 2024 984 2023 985 2012 986 2021 1017...

result:

points 0.50 Partially Correct | type = 2

Test #37:

score: 5
Acceptable Answer
time: 153ms
memory: 80892kb

input:

50
9167 6418302 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51...

output:

2971 7562 3209 7561 3199 7560 3200 7559 3201 7558 3202 7557 3203 7556 3204 7555 3205 7554 3206 7553 3207 7552 3208 7551 3198 7550 3210 7549 3211 7548 3212 7547 3213 7546 3214 7545 3215 7544 3216 7543 3217 7542 3218 7574 3219 7584 3187 7583 3177 7582 3178 7581 3179 7580 3180 7579 3181 7578 3182 7577 ...

result:

points 0.50 Partially Correct | type = 2

Test #38:

score: 5
Acceptable Answer
time: 172ms
memory: 84848kb

input:

20
24105 203761007 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

12050 12056 12051 12055 12052 12054 2 12119 11988 12071 12036 12072 12035 12073 12034 12074 12033 12075 12032 12076 12031 12077 12030 12078 12029 12079 12028 12080 12027 12081 12026 12082 12025 12083 12024 12084 12023 12085 12022 12160 11947 12168 11939 12167 11940 12166 11941 12165 11942 12164 1194...

result:

points 0.50 Partially Correct | type = 2

Test #39:

score: 5
Acceptable Answer
time: 223ms
memory: 91616kb

input:

10
48337 97528 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
...

output:

24168 24167 24166 24165 24164 24163 24162 24161 24160 24159 24158 24157 24156 24155 24154 24153 24152 24151 24150 24149 24148 24147 24146 24145 24144 24143 24142 24141 24140 24139 24138 24137 24136 24135 24134 24133 24132 24131 24130 24129 24128 24127 24126 24125 24124 24123 24122 24121 24120 24119 ...

result:

points 0.50 Partially Correct | type = 2

Test #40:

score: 10
Accepted
time: 178ms
memory: 91688kb

input:

10
48412 869174248 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

18219 36439 18227 36440 18226 36441 18225 36442 18224 36443 18223 36444 18222 36445 18221 36446 18220 36447 18228 36448 18218 36449 18217 36450 18216 36451 18215 36452 18214 36453 18213 36454 18212 36455 18211 36429 18237 36421 18245 36422 18244 36423 18243 36424 18242 36425 18241 36426 18240 36427 ...

result:

ok Accepted.

Test #41:

score: 10
Accepted
time: 171ms
memory: 104212kb

input:

5
91193 4099928074 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

30614 61026 30604 61027 30605 61028 30606 61029 30607 61030 30608 61031 30609 61032 30610 61033 30611 61034 30612 61035 30613 61025 30603 61024 30615 61023 30616 61022 30617 61021 30618 61020 30619 61019 30620 61018 30621 61017 30622 61016 30623 61015 30624 61047 30592 61071 30582 61060 61061 61062 ...

result:

ok Accepted.

Subtask #6:

score: 6
Acceptable Answer

Dependency #3:

50%
Acceptable Answer

Test #42:

score: 12
Accepted
time: 11ms
memory: 77992kb

input:

5
28 65 1
11 9
9 16
16 22
22 21
21 12
14 5
5 27
7 4
4 28
28 20
20 24
8 1
1 25
13 3
3 6
6 2
2 15
17 18
18 19
19 12
12 23
15 24
24 25
25 10
10 27
27 23
23 26
30 74 1
24 2
21 25
4 26
26 15
15 6
6 18
5 20
20 19
19 12
12 8
17 3
3 13
13 29
29 9
27 7
7 14
11 1
1 8
8 16
16 30
30 28
22 2
10 28
28 14
14 18
18...

output:

1 23 12 19 18 17 21 22 16 9 11 26 27 5 10 24 2 3 20 28 4 7 14 25 8 15 6 13 
26 14 7 27 8 6 1 11 28 10 30 16 12 19 20 5 18 15 4 9 2 22 24 25 21 23 29 13 3 17 
16 12 17 20 1 2 4 10 7 19 5 14 21 27 22 9 11 18 6 3 25 26 23 15 13 24 8 
22 25 2 9 17 6 16 10 21 28 1 19 7 4 11 5 26 29 15 30 13 14 8 20 3 23 ...

result:

ok Accepted.

Test #43:

score: 12
Accepted
time: 11ms
memory: 78200kb

input:

5
27 286 2
22 12
25 2
2 15
15 3
20 16
13 26
27 10
10 21
21 1
1 23
19 24
24 4
4 7
7 26
26 6
6 3
3 18
18 23
11 8
8 9
9 14
14 17
17 12
12 16
16 23
23 5
27 51 2
11 18
18 19
12 10
10 2
4 3
3 5
15 23
23 6
6 9
22 7
26 24
24 13
13 14
14 2
25 7
16 20
20 19
19 17
17 8
1 7
8 2
2 9
9 7
7 5
5 27
27 21
29 56 2
29...

output:

-1
-1
13 6 22 11 17 16 3 15 18 23 27 4 29 2 21 12 14 20 26 1 19 24 25 7 8 10 9 28 5 
-1
-1

result:

ok Accepted.

Test #44:

score: 6
Acceptable Answer
time: 12ms
memory: 78004kb

input:

5
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2

output:

-1
-1
1 
-1
1 

result:

points 0.50 Partially Correct | type = 2

Test #45:

score: 12
Accepted
time: 12ms
memory: 78200kb

input:

5
27 172 1
17 8
8 13
13 7
7 22
22 3
3 18
15 20
2 25
27 9
9 10
14 6
21 4
4 26
26 10
10 25
25 12
16 19
24 19
12 19
19 1
11 23
23 20
20 6
6 1
5 18
18 1
29 209 1
9 7
7 16
16 12
12 4
4 24
19 25
28 17
17 6
6 1
1 11
11 13
29 15
15 21
5 22
22 27
14 13
13 20
8 24
24 21
21 2
2 25
25 27
27 26
26 23
23 20
20 3
...

output:

1 27 5 10 18 4 3 22 21 7 26 13 25 2 8 12 23 19 11 16 20 24 15 9 6 17 14 
15 3 10 21 29 20 8 13 24 11 4 1 12 16 17 9 6 28 7 27 5 14 22 19 26 25 23 2 18 
5 2 8 28 21 17 1 25 11 26 7 27 9 23 6 13 18 15 3 14 4 22 24 10 16 12 19 20 
7 26 4 16 25 13 5 17 11 21 18 24 8 9 20 1 15 14 22 2 3 19 10 12 6 27 23 ...

result:

ok Accepted.

Test #46:

score: 12
Accepted
time: 11ms
memory: 78228kb

input:

5
27 136 1
1 11
11 10
10 8
2 26
24 20
25 27
27 22
22 15
16 9
18 21
21 7
7 5
5 14
14 3
3 9
9 8
8 6
17 26
26 6
13 15
15 23
23 6
6 20
20 12
12 19
4 19
27 196 2
1 12
12 4
4 27
27 14
19 15
15 8
18 7
7 10
10 16
9 2
23 13
26 17
5 25
22 2
6 16
16 25
25 8
8 14
14 21
21 17
17 13
13 24
24 11
11 3
3 2
2 20
28 1...

output:

6 12 19 4 21 18 24 7 20 27 1 25 10 22 11 15 8 13 16 23 9 3 26 14 2 5 17 
18 1 7 4 2 27 9 12 22 19 20 8 3 15 24 11 5 13 25 23 6 17 16 26 10 21 14 
12 9 25 27 4 1 8 20 23 6 10 13 17 15 18 19 26 22 11 3 16 7 28 2 24 5 14 21 
24 8 12 22 26 6 9 21 25 2 28 4 5 10 11 23 7 16 19 3 18 20 14 27 15 13 1 17 
13...

result:

ok Accepted.

Test #47:

score: 6
Acceptable Answer
time: 19ms
memory: 78224kb

input:

5
30 66 1
20 19
19 8
8 18
18 24
28 17
3 15
23 16
12 29
29 1
1 11
11 25
25 21
21 2
4 5
5 9
9 14
7 10
10 2
2 13
6 15
15 17
17 13
13 27
22 27
26 27
27 14
30 24
24 16
16 14
29 172 2
20 7
7 27
27 11
26 14
14 17
22 8
29 1
1 21
5 9
24 16
12 18
4 19
19 3
3 25
25 21
23 28
2 8
28 8
8 15
10 18
18 21
21 16
6 9
...

output:

16 23 24 18 8 19 20 30 17 6 28 22 2 26 13 10 7 15 3 21 25 11 1 29 12 27 14 9 5 4 
5 29 6 11 24 27 16 13 20 10 7 12 17 18 26 21 14 1 15 25 28 23 3 2 4 22 19 8 9 
8 10 4 3 15 18 14 5 21 11 20 28 12 9 22 13 26 27 17 1 23 19 7 24 25 2 16 6 
18 2 16 9 1 27 26 7 20 5 3 10 22 14 17 12 4 13 15 21 24 23 19 1...

result:

points 0.50 Partially Correct | type = 2

Test #48:

score: 12
Accepted
time: 22ms
memory: 77988kb

input:

5
28 164 1
24 18
18 25
25 7
23 11
11 3
10 16
16 2
2 27
27 21
22 9
9 6
1 28
28 19
19 17
17 7
7 12
20 21
21 3
3 6
6 13
8 4
4 12
15 12
12 13
14 13
13 5
26 5
28 153 1
18 4
13 2
25 24
24 7
27 12
10 19
19 9
9 8
15 11
11 6
6 16
16 20
20 1
1 23
23 2
5 8
8 4
4 17
28 21
26 21
21 14
14 3
3 12
12 7
7 2
2 17
17 ...

output:

22 8 9 4 6 23 15 11 12 3 25 20 18 21 7 2 17 10 19 16 1 14 13 24 5 26 27 28 
3 15 12 11 27 19 24 10 25 9 7 8 6 17 4 5 18 23 22 2 13 1 14 28 20 21 26 16 
21 27 16 4 28 25 18 2 6 17 19 10 8 26 20 3 12 1 14 7 23 13 15 5 24 22 11 9 
23 30 11 17 20 27 14 2 4 21 3 8 19 15 16 25 24 6 26 5 1 29 10 7 13 12 22...

result:

ok Accepted.

Test #49:

score: 6
Acceptable Answer
time: 7ms
memory: 77992kb

input:

5
28 90 2
28 3
8 6
26 11
11 15
15 16
5 12
1 27
27 13
21 9
9 22
14 20
4 2
10 18
18 19
19 16
23 6
6 13
13 12
17 16
25 20
20 12
12 3
3 2
2 24
24 22
22 16
16 7
28 92 1
1 11
11 24
14 3
4 10
10 23
23 2
2 26
22 5
15 17
17 18
18 20
20 19
19 28
28 16
12 3
3 9
25 5
6 21
21 16
16 7
9 24
24 13
7 26
26 8
13 27
2...

output:

13 6 8 23 1 4 16 7 11 26 3 20 14 15 28 19 18 10 12 5 27 25 24 22 9 21 17 2 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
3 27 20 11 13 23 17 25 1 12 2 16 21 8 15 7 9 10 4 5 19 26 18 14 24 22 6 
7 3 5 18 1 21 25 26 14 17 28 24 8 6 10 4 23 9 16 20 12 27 11 29 15 13 2 19 ...

result:

points 0.50 Partially Correct | type = 2

Test #50:

score: 6
Acceptable Answer
time: 8ms
memory: 77992kb

input:

5
27 256 2
1 14
14 12
12 24
24 17
17 21
21 22
22 4
19 10
10 15
25 9
2 11
5 20
20 7
18 15
15 27
27 23
8 4
6 4
4 13
13 9
9 11
11 16
16 26
26 3
3 7
7 23
27 174 2
18 23
23 14
27 4
4 3
9 8
8 16
16 15
22 24
24 11
11 17
25 1
1 2
2 6
6 10
12 19
19 13
13 15
15 5
21 5
26 3
3 14
14 20
20 17
17 7
7 5
5 10
27 17...

output:

22 2 16 14 26 25 3 9 7 13 6 5 8 20 4 23 21 27 17 18 24 15 12 19 1 10 11 
9 24 16 20 15 14 19 18 12 26 13 3 8 27 21 4 2 25 23 1 7 6 17 11 10 22 5 
9 10 22 27 7 12 26 8 16 3 25 19 14 11 18 2 21 17 4 1 20 6 23 24 5 15 13 
27 26 11 6 12 20 1 7 2 13 15 28 5 8 30 22 19 3 23 29 25 16 9 21 14 4 17 10 18 24 ...

result:

points 0.50 Partially Correct | type = 2

Test #51:

score: 12
Accepted
time: 12ms
memory: 77980kb

input:

5
27 75 1
19 4
22 14
15 23
23 1
1 26
26 9
9 13
6 18
18 7
7 16
20 27
25 10
10 21
17 27
12 13
3 11
11 5
8 14
24 4
4 16
16 5
5 14
14 13
13 27
27 21
21 2
29 156 2
12 21
21 29
29 7
7 22
22 27
20 10
10 1
1 24
24 25
25 26
26 23
5 6
6 14
9 17
19 4
11 4
3 14
16 8
28 15
15 8
8 17
17 14
14 23
23 4
18 27
13 27
...

output:

8 16 4 19 24 18 6 23 5 3 7 9 26 22 13 12 27 17 20 21 2 10 25 1 15 14 11 
15 28 20 16 1 8 24 21 25 12 26 29 10 7 17 22 6 27 14 3 5 9 18 4 2 11 19 13 23 
1 15 16 17 11 6 28 4 10 26 3 23 12 14 27 20 2 9 7 5 24 18 19 13 21 8 29 22 25 
7 6 20 5 24 13 11 8 12 25 3 17 2 18 26 23 15 22 10 9 4 16 1 27 14 28 ...

result:

ok Accepted.

Test #52:

score: 12
Accepted
time: 18ms
memory: 78040kb

input:

5
27 151 1
27 26
26 17
4 8
10 16
22 12
12 9
3 23
23 15
15 11
11 20
20 24
19 25
14 21
21 17
17 1
1 24
13 2
7 16
6 16
16 5
5 25
25 9
9 24
24 8
8 2
2 18
30 212 2
16 30
30 22
22 28
28 14
14 2
2 15
19 4
4 29
17 9
9 5
7 12
11 1
13 25
18 26
26 27
24 5
5 21
8 20
20 25
25 29
29 23
10 12
6 15
15 23
23 12
12 2...

output:

24 18 6 13 16 8 23 4 3 2 15 22 11 9 20 12 21 19 14 25 17 5 26 10 27 7 1 
13 28 20 10 8 12 7 4 27 19 18 29 26 25 3 6 11 15 1 2 21 14 24 22 5 16 17 30 9 23 
15 28 3 25 27 8 11 29 19 10 14 26 30 13 21 22 24 4 7 17 12 9 20 1 16 18 23 2 6 5 
6 20 16 5 2 12 21 19 22 25 24 13 18 26 9 1 11 23 27 14 15 3 4 1...

result:

ok Accepted.

Subtask #7:

score: 9
Acceptable Answer

Dependency #4:

50%
Acceptable Answer

Dependency #6:

50%
Acceptable Answer

Test #53:

score: 9
Acceptable Answer
time: 15ms
memory: 78212kb

input:

2000
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 1
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 2
1 0 1
1...

output:

1 
-1
1 
1 
-1
-1
1 
1 
-1
1 
1 
1 
-1
1 
1 
1 
-1
1 
1 
1 
1 
-1
1 
-1
-1
-1
1 
1 
1 
1 
1 
1 
1 
-1
-1
1 
-1
1 
-1
1 
-1
1 
-1
-1
-1
-1
-1
1 
-1
1 
1 
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
1 
1 
-1
1 
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
1 
1 
1 
1 
-1
1 
-1
1 
-1
-1
-1
1 
-1
1 
-1
-1
1 
1 
-1
-1
1 
...

result:

points 0.50 Partially Correct | type = 2

Test #54:

score: 18
Accepted
time: 15ms
memory: 78292kb

input:

5
369 9452 2
107 345
345 96
96 194
194 277
277 313
313 126
126 116
338 97
97 40
40 253
199 341
341 140
140 155
92 37
37 307
307 32
32 145
161 275
64 133
18 43
113 73
73 322
322 85
85 328
328 159
159 1
364 299
299 235
235 2
2 274
347 335
335 367
104 108
108 153
76 174
246 154
154 203
203 93
93 284
28...

output:

95 234 82 180 301 191 210 55 145 72 32 160 307 115 92 261 37 317 183 49 249 99 211 215 6 80 349 14 168 316 33 369 12 293 58 200 71 43 18 213 28 86 177 272 286 127 214 195 189 152 252 227 259 22 262 291 124 221 17 54 238 120 239 31 157 188 78 356 285 269 220 315 141 158 362 89 11 288 323 66 23 266 14...

result:

ok Accepted.

Test #55:

score: 18
Accepted
time: 19ms
memory: 78564kb

input:

1
1981 59778 1
581 1357
1357 1114
1319 822
822 1185
1143 365
619 708
708 1424
1424 1489
1489 1936
1936 1740
1789 1497
1497 387
387 1272
1272 485
1448 418
418 893
1011 1305
1305 176
1593 915
915 1594
1594 1432
1432 1794
1794 837
17 704
704 1542
1270 802
802 1879
1427 608
608 1723
1723 1288
1288 779
7...

output:

998 1311 97 1223 764 1283 1250 1819 1477 537 58 201 379 838 975 180 1849 820 210 1493 1071 1381 1831 1004 189 699 1409 437 425 1072 1733 447 1932 1406 227 1943 1796 535 990 1576 1564 1182 1888 71 1118 545 82 1028 560 584 469 1530 688 1199 1861 1236 226 289 93 955 1558 1395 1249 1906 357 1979 604 750...

result:

ok Accepted.

Test #56:

score: 18
Accepted
time: 15ms
memory: 78384kb

input:

1
1998 29319 1
93 1888
1888 701
701 643
643 1166
294 975
975 574
574 19
19 1224
1435 1480
72 1942
1707 613
613 1451
1272 769
1683 1050
1372 1242
1242 901
191 230
1702 562
562 883
1086 1964
1964 1852
1852 1955
1955 310
1165 1905
54 557
557 1182
1182 973
973 878
878 1950
1950 551
551 1473
1473 1921
11...

output:

641 1237 879 1936 208 998 1918 317 1791 1314 60 98 1037 1962 416 6 892 628 1007 1587 840 737 1698 1525 119 1039 831 57 1001 133 1744 175 367 1945 1597 206 1625 18 31 1238 152 1405 1412 75 238 700 1694 1674 653 1393 1523 853 1176 1270 1635 1964 509 1086 1737 552 381 1876 160 514 1425 992 1852 596 771...

result:

ok Accepted.

Test #57:

score: 18
Accepted
time: 17ms
memory: 78328kb

input:

1
1916 61288 2
395 1027
1610 1787
1787 357
189 139
139 675
675 1158
1158 1868
1868 1196
719 1579
1131 810
810 227
227 475
475 1060
1092 1602
1298 760
1390 211
211 1839
1839 99
99 618
618 1754
1754 1682
1682 529
529 1460
1555 1589
1589 152
152 1665
1665 1781
1649 1487
1487 870
870 144
144 934
750 162...

output:

1195 761 1384 1586 1775 1453 1838 1906 182 1293 165 1570 722 94 1157 1329 1845 656 1790 528 258 416 1731 1904 998 912 1659 438 14 882 1633 1874 887 1084 1107 1407 766 1735 1618 485 1117 903 1857 1579 240 719 62 1601 263 503 536 588 1143 636 1465 1440 1705 205 1175 242 106 823 1294 740 586 937 12 559...

result:

ok Accepted.

Test #58:

score: 18
Accepted
time: 13ms
memory: 78348kb

input:

1
1835 91921 1
792 896
527 544
544 1461
1461 1426
1426 399
1350 1246
1246 496
496 227
227 799
799 546
945 779
779 418
1712 108
944 949
949 279
552 73
1311 1756
749 815
815 838
838 802
802 242
242 149
1482 1459
568 180
180 506
506 1270
758 1417
1417 203
898 178
178 386
386 920
920 467
715 76
76 1111
...

output:

714 171 1392 1787 126 624 1135 915 177 632 232 1233 377 1191 1650 109 1193 718 1319 1776 97 1745 446 1529 1592 81 1055 279 459 1803 63 1534 432 455 361 331 103 1550 348 499 1605 1477 133 1018 408 973 1730 1273 1680 533 1816 1351 1167 663 1692 959 1040 721 399 1004 1100 614 412 892 1426 53 1461 1043 ...

result:

ok Accepted.

Test #59:

score: 18
Accepted
time: 7ms
memory: 77988kb

input:

50
39 327 2
11 9
9 24
32 3
3 23
23 20
20 18
18 31
37 6
39 25
4 14
14 29
29 19
19 35
38 17
17 33
10 15
16 30
30 21
21 12
12 8
8 1
1 26
28 22
34 31
22 15
15 13
13 24
5 25
25 27
36 35
35 24
24 7
7 26
26 33
33 6
6 2
2 31
31 27
39 501 2
5 15
15 8
6 23
23 4
17 32
32 34
11 9
9 35
35 14
13 2
18 25
25 24
24 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
6 14 18 7 21 28 3 32 13 5 37 2 8 38 12 20 39 36 26 30 31 9 16 11 1 35 4 10 15 25 29 33 34 19 27 24 22 23 17 
19 35 7 22 32 23 13 25 5 20 16 38 18 27 29 9 11 8 21 6 2 1 14 31 12 26 36 10 4 3 33 30 15 24 34 28 37 17 
-1
12 10 15 21 11 4 5 34 22 33 3 30 27 20 9 16 17 35 18 19 8 ...

result:

ok Accepted.

Test #60:

score: 18
Accepted
time: 8ms
memory: 78048kb

input:

330
6 14 2
4 3
3 1
1 5
5 2
2 6
6 8 1
1 3
3 6
6 5
2 5
5 4
6 12 1
1 4
4 5
2 3
3 5
5 6
6 14 2
1 6
3 2
2 5
5 6
6 4
6 6 1
2 1
1 5
5 6
6 3
3 4
6 14 2
1 5
5 2
2 6
4 6
6 3
6 10 2
6 2
2 1
3 4
4 1
1 5
6 9 1
2 1
1 5
5 4
4 3
3 6
6 12 2
6 2
2 3
3 4
4 1
1 5
6 10 2
3 2
2 5
5 4
4 1
1 6
6 14 2
5 2
2 3
3 1
1 4
6 4
6 ...

output:

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

result:

ok Accepted.

Test #61:

score: 9
Acceptable Answer
time: 16ms
memory: 78296kb

input:

100
19 44 1
13 18
18 10
10 5
9 7
16 6
6 8
8 3
2 17
17 1
11 19
15 19
4 14
14 5
5 1
1 7
7 19
19 3
3 12
20 96 1
14 2
2 9
7 16
16 10
8 20
20 5
19 11
11 1
15 4
4 3
3 10
10 5
5 9
9 12
12 13
18 1
1 17
6 13
13 17
19 106 2
4 12
12 16
16 19
19 6
6 15
9 5
5 8
7 14
11 18
18 3
3 8
8 17
17 2
10 2
2 15
1 14
14 15
...

output:

19 12 11 3 8 6 16 5 18 14 4 15 9 7 1 10 13 17 2 
10 3 17 18 16 7 13 5 6 20 12 9 2 8 14 11 4 19 15 1 
4 3 16 18 19 8 6 9 12 5 14 11 7 10 1 2 13 17 15 
12 16 9 18 1 4 20 6 10 14 2 8 17 7 11 19 13 3 15 5 
11 5 12 1 2 4 6 17 3 10 15 16 18 7 14 8 19 9 13 20 
16 18 13 7 8 3 17 6 15 10 11 4 2 14 12 19 9 5 ...

result:

points 0.50 Partially Correct | type = 2

Test #62:

score: 18
Accepted
time: 8ms
memory: 78228kb

input:

100
19 59 1
7 2
8 16
16 11
11 3
3 5
5 4
15 1
19 6
9 12
14 1
18 2
2 4
4 6
6 13
13 1
1 17
17 12
12 10
18 104 2
3 17
1 14
14 11
18 2
5 6
6 4
4 15
15 10
10 7
7 8
8 17
17 16
16 11
11 13
13 9
9 2
2 12
19 53 1
12 9
8 11
3 5
5 13
13 7
7 2
2 16
19 1
17 14
14 16
15 6
6 9
9 1
4 1
1 16
16 11
11 10
10 18
18 29 1...

output:

14 5 11 8 17 12 9 10 2 6 13 15 19 4 7 3 16 18 1 
8 3 2 12 6 18 5 9 4 13 15 11 7 10 16 14 1 17 
13 3 1 4 6 5 19 7 9 15 12 16 2 11 8 10 18 14 17 
16 7 2 13 18 14 11 12 5 15 3 17 9 4 6 1 10 8 
16 5 12 15 18 3 8 9 14 2 19 17 1 11 6 10 7 4 13 20 
9 15 8 1 10 19 2 5 6 13 14 4 16 3 18 11 17 7 12 
20 7 13 1...

result:

ok Accepted.

Test #63:

score: 9
Acceptable Answer
time: 7ms
memory: 77956kb

input:

20
99 794 1
32 56
34 98
98 86
2 37
37 13
13 22
22 47
82 95
49 39
5 91
28 80
50 15
92 26
26 93
93 59
88 9
46 79
79 14
14 38
38 97
97 83
83 75
75 20
20 76
76 33
54 25
25 72
72 18
89 58
58 66
24 27
27 87
36 10
10 3
3 30
30 85
85 45
45 55
73 71
81 35
35 17
67 69
74 40
40 63
51 16
7 42
42 11
11 29
77 64
...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
94 5 31 25 ...

result:

points 0.50 Partially Correct | type = 2

Test #64:

score: 18
Accepted
time: 15ms
memory: 78224kb

input:

20
90 624 1
35 32
81 1
1 51
46 27
27 13
84 58
77 48
48 61
64 42
42 29
29 31
31 25
25 67
38 10
10 2
2 57
12 3
50 66
66 5
5 80
80 60
60 15
15 70
70 9
9 22
72 68
68 76
79 20
20 73
73 54
54 59
59 21
21 45
45 52
52 82
63 55
55 37
37 74
28 90
14 19
19 43
43 41
41 62
62 26
4 71
7 82
23 89
56 11
30 36
78 39...

output:

77 72 18 48 90 53 26 12 25 31 29 42 64 59 73 67 37 1 34 16 75 3 74 4 40 71 24 51 81 39 17 78 44 69 6 2 22 36 8 33 30 9 70 57 10 38 88 82 7 52 58 11 56 84 15 60 80 45 66 50 21 54 20 79 5 83 89 23 87 85 65 55 63 49 13 32 46 35 27 47 62 41 43 19 14 76 86 68 28 61 
54 34 90 74 21 66 94 17 7 82 40 18 71 ...

result:

ok Accepted.

Test #65:

score: 9
Acceptable Answer
time: 15ms
memory: 78028kb

input:

20
98 788 2
78 38
38 90
8 69
69 47
47 62
62 6
35 92
92 57
20 70
11 17
17 89
28 5
5 68
68 73
73 64
26 42
31 46
46 86
56 21
30 95
60 33
33 13
13 22
40 65
65 4
4 15
15 58
71 80
80 48
52 49
49 27
27 98
98 36
94 82
79 63
63 93
93 85
85 67
67 91
84 9
9 75
24 29
51 96
96 1
23 87
87 43
43 59
59 54
54 76
76 ...

output:

43 40 29 4 19 53 6 88 62 47 15 8 65 98 27 49 52 41 36 10 76 54 59 63 23 39 87 79 69 93 96 85 32 67 51 91 1 44 21 81 56 33 38 60 78 22 13 25 12 90 72 16 64 74 7 80 97 71 70 18 42 26 77 20 55 61 48 89 83 11 3 17 50 46 31 5 86 28 9 68 75 84 73 34 45 37 94 30 82 14 2 57 66 92 35 24 95 58 
29 75 60 23 65...

result:

points 0.50 Partially Correct | type = 2

Test #66:

score: 18
Accepted
time: 11ms
memory: 77996kb

input:

5
381 3720 1
140 69
69 271
192 329
18 358
358 164
164 336
336 75
75 282
282 222
14 12
12 321
321 236
236 272
272 311
150 121
121 372
186 257
257 370
370 91
201 92
92 356
356 60
60 202
273 317
129 279
279 110
251 253
77 11
11 22
22 175
175 40
40 157
161 287
287 242
345 235
228 364
364 226
103 246
246...

output:

82 246 230 133 279 129 139 235 78 330 276 345 248 159 366 270 8 46 97 10 310 312 325 221 206 320 161 6 242 354 216 305 120 184 179 205 61 66 343 190 177 288 292 45 204 315 303 281 33 339 314 266 89 106 121 152 284 280 52 351 203 238 80 372 5 214 150 55 194 81 199 294 85 333 332 347 70 331 306 49 307...

result:

ok Accepted.

Test #67:

score: 18
Accepted
time: 15ms
memory: 78272kb

input:

5
376 5912 1
256 172
156 371
371 300
133 115
115 138
176 1
1 342
342 27
27 370
370 243
243 260
178 337
337 233
233 116
116 372
108 294
53 331
331 134
134 202
202 247
247 259
259 208
350 3
3 15
15 119
119 89
89 31
31 5
237 104
104 278
278 9
9 324
324 231
151 106
106 314
314 363
111 367
126 46
46 43
1...

output:

47 224 76 244 319 309 83 16 74 326 373 180 189 213 253 136 315 63 18 80 67 175 346 183 92 140 69 56 229 128 43 112 317 263 301 118 46 126 33 196 220 82 236 214 125 86 162 234 212 262 203 356 248 48 226 274 127 307 344 159 312 228 164 345 286 130 95 181 291 20 246 182 81 240 310 30 311 144 270 110 36...

result:

ok Accepted.

Subtask #8:

score: 5
Acceptable Answer

Dependency #7:

50%
Acceptable Answer

Test #68:

score: 5
Acceptable Answer
time: 23ms
memory: 77984kb

input:

100000
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1...

output:

-1
-1
1 
-1
1 
1 
-1
1 
1 
-1
-1
1 
-1
-1
-1
1 
-1
1 
1 
-1
1 
-1
-1
1 
1 
1 
1 
-1
1 
-1
-1
1 
1 
1 
-1
-1
1 
-1
1 
-1
1 
1 
1 
1 
-1
-1
-1
-1
-1
-1
-1
1 
1 
1 
-1
-1
1 
-1
1 
-1
-1
1 
-1
1 
1 
1 
-1
1 
1 
-1
1 
1 
1 
-1
-1
-1
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
1 
-1
-1
1 
1 
-1
1 
1 
1 
-1
1 
-1
...

result:

points 0.50 Partially Correct | type = 2

Test #69:

score: 10
Accepted
time: 50ms
memory: 79292kb

input:

20
4739 5853376 2
241 1557
2727 144
828 4540
4356 4276
2664 1248
3140 3044
2673 2465
4472 4588
4088 1582
1402 837
249 2576
4222 2011
4326 3478
618 1837
2221 2758
4294 4571
4420 99
783 4166
2904 2230
2043 3395
4697 394
1658 1677
2315 931
4132 173
2863 4183
1156 2961
3832 4207
4175 2577
3526 2571
3844...

output:

2552 8 1873 2744 1682 1061 2992 3227 352 3541 1655 3951 3867 4397 4463 287 215 2763 2513 370 1627 1531 3147 2756 866 1925 1983 4019 1838 3757 4654 2281 110 819 2422 4377 637 1878 2292 663 4439 1323 1596 1678 2019 2105 3143 4718 1508 139 1183 3068 73 2655 3195 4340 2000 3203 1791 3316 1189 1330 349 3...

result:

ok Accepted.

Test #70:

score: 10
Accepted
time: 44ms
memory: 80468kb

input:

10
9775 28387496 2
4111 1845
5328 8463
5658 5847
3140 4296
2304 2863
3059 9597
3416 4942
4155 8323
5427 420
4277 6009
6681 2156
2015 6300
3901 7434
3626 7491
34 8881
2933 1589
2493 3247
3049 2124
7966 8151
7298 5798
4005 1543
6558 7955
7205 7231
6962 8747
9115 2347
6678 2313
6313 5913
5718 2087
4601...

output:

6311 4213 7832 7570 15 3116 1900 2466 465 9199 9522 3892 8580 6272 9531 5102 8387 2323 6632 909 3399 8232 5135 59 3962 6477 9132 7686 4309 461 7757 4850 5453 3975 197 82 6193 7861 7482 2629 7415 8149 3937 2436 7049 7388 3457 6030 6427 2873 7340 6250 5153 9765 3721 3173 5694 8120 780 9576 516 7225 89...

result:

ok Accepted.

Test #71:

score: 10
Accepted
time: 74ms
memory: 82612kb

input:

5
18424 102019945 1
6009 5000
688 5707
7377 2483
17135 11887
11730 10212
8202 2298
10379 4241
11435 9713
12686 1606
7194 701
4130 17140
12866 7314
5553 17608
17154 14894
476 15049
8664 31
16244 10749
7130 14423
15077 15440
3494 14841
14846 5537
15852 16565
9158 1139
9750 14771
16068 5101
5313 2422
9...

output:

4611 3728 15937 2805 15136 8137 16121 7233 12643 6847 9652 16167 3822 2572 7635 18174 11979 17939 3462 14227 15899 4439 1661 16605 635 12680 15574 6611 5453 140 4994 553 13300 18013 10527 13066 434 15816 927 18061 2031 17521 2169 7139 1930 12378 5021 7624 6486 10068 5487 17344 12774 10938 1663 13267...

result:

ok Accepted.

Test #72:

score: 10
Accepted
time: 56ms
memory: 85620kb

input:

3
31442 1897522 2
227 18045
19811 21817
17841 21143
23712 9546
31355 10107
2019 12690
10655 15526
21289 27919
21190 18604
762 28189
31092 22046
941 7045
25679 6271
341 5776
16779 28120
396 3989
18232 11559
24181 31300
6960 8713
12363 9404
18439 27196
16813 9762
10651 332
3494 20107
13995 26937
2428 ...

output:

3483 4604 5343 5614 22779 25960 15152 31150 15601 7807 12097 20360 17748 3917 13680 18830 20165 18214 30595 2810 30264 3686 3752 14994 17820 17205 18394 2508 22661 4851 12625 20591 23914 30640 30857 2613 5685 11738 8037 5909 23177 1781 23698 7594 9837 30999 11152 912 28956 13721 27102 11534 23093 13...

result:

ok Accepted.

Test #73:

score: 10
Accepted
time: 78ms
memory: 85336kb

input:

3
32308 277196163 1
28236 28059
13478 9068
28454 28849
16817 246
11618 9818
28123 4662
20902 9080
13907 9158
5441 10539
27228 25652
13268 4496
13075 15781
9747 15408
24294 13278
29091 28311
3433 30055
20111 22336
24462 24005
16412 2106
17953 18082
11530 16617
17947 4128
2459 26569
9247 18592
19713 1...

output:

3391 4277 20392 30979 8006 12722 3152 19040 20090 28559 7659 19182 4006 25472 12993 24278 24556 9998 16733 18802 1844 631 2173 28521 21296 29081 29697 30063 15235 12388 24524 26450 911 25942 12038 11444 11102 17594 16657 12458 16660 25412 23567 30630 22541 18956 5121 23956 24042 1765 28562 11331 274...

result:

ok Accepted.

Test #74:

score: 5
Acceptable Answer
time: 23ms
memory: 78100kb

input:

233
427 58203 1
279 292
169 156
224 109
215 332
268 84
335 383
381 6
166 228
261 252
47 241
118 197
136 140
31 80
329 149
241 351
387 61
400 208
60 219
187 199
116 365
420 186
288 98
427 55
391 305
192 40
88 339
278 308
87 322
221 185
415 360
285 295
422 140
10 218
359 92
15 286
286 33
102 396
246 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
275 135 210 290 180 201 42 262 148 343 91 342 110 140 345 80 269 339 160 33 240 37 118 292 313 335 242 231 146 365 22 2 30 97 243 360 133 35 108 358 366 192 134 88 176 5 23 68 76 280 165 60 79 14 378 122 309 50 252 382 72 254 119 184 193 212 304 161 351 337 8 9...

result:

points 0.50 Partially Correct | type = 2

Test #75:

score: 5
Acceptable Answer
time: 31ms
memory: 78228kb

input:

10000
9 16 2
4 8
1 3
3 5
5 8
8 6
6 9
9 2
2 7
10 29 1
5 7
8 2
3 10
10 1
1 6
6 4
4 9
9 2
2 7
10 38 1
10 1
8 9
2 1
1 3
3 5
5 9
9 7
7 4
4 6
10 22 1
5 6
2 6
7 1
1 3
3 6
6 4
4 8
8 10
10 9
9 27 1
8 3
9 6
6 3
3 1
1 4
4 2
2 7
7 5
9 20 2
8 6
6 3
4 5
5 3
3 9
9 2
2 1
1 7
10 13 1
3 10
10 5
5 1
1 4
4 6
6 9
9 2
2 ...

output:

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

result:

points 0.50 Partially Correct | type = 2

Test #76:

score: 5
Acceptable Answer
time: 36ms
memory: 77948kb

input:

5000
20 66 2
19 1
1 15
4 8
3 16
12 17
17 8
13 8
8 20
20 6
6 2
2 5
5 9
9 14
14 11
11 7
7 15
15 16
16 18
18 10
19 37 1
4 10
6 16
10 1
11 3
3 13
13 15
12 17
17 8
8 2
2 18
18 7
7 16
16 1
1 19
19 9
9 14
14 15
15 5
18 99 1
8 18
16 14
12 2
17 11
10 3
11 4
2 7
7 9
9 4
4 1
1 14
14 18
18 6
6 3
3 13
13 5
5 15
...

output:

7 6 8 4 13 12 15 1 19 16 3 18 10 20 17 11 5 2 14 9 
9 14 15 5 13 3 11 10 4 16 6 18 7 2 8 17 12 1 19 
1 16 14 2 5 12 15 7 13 9 3 4 10 11 17 18 6 8 
6 13 20 7 2 3 9 11 12 16 14 17 10 8 19 18 1 15 5 4 
16 3 9 6 2 15 5 11 13 8 12 19 7 1 4 14 10 17 18 
6 10 16 9 17 13 1 18 11 15 14 4 2 8 7 5 12 3 
4 6 9 ...

result:

points 0.50 Partially Correct | type = 2

Test #77:

score: 5
Acceptable Answer
time: 36ms
memory: 78008kb

input:

2000
47 252 2
41 8
34 25
5 38
45 18
46 12
44 12
40 21
11 10
14 47
19 7
42 35
35 2
13 39
3 23
10 31
31 16
16 15
15 30
30 7
7 26
26 2
2 27
27 25
25 39
39 38
38 4
4 20
20 24
24 23
23 21
21 32
32 6
6 17
17 33
33 8
8 29
29 1
1 28
28 37
37 22
22 47
47 12
12 18
18 9
9 43
43 36
46 682 2
42 4
6 46
25 16
5 43...

output:

3 47 46 2 7 19 30 15 16 31 10 11 14 35 42 22 12 9 36 44 18 43 45 26 8 29 1 28 37 41 27 6 17 33 25 24 20 4 38 5 39 13 34 21 32 40 23 
14 27 1 40 42 30 4 6 9 13 46 29 12 18 5 19 43 41 2 20 22 32 8 25 26 16 34 44 3 7 23 37 35 28 38 31 17 11 39 21 36 15 24 45 33 10 
23 46 6 17 38 41 34 7 30 45 21 11 5 2...

result:

points 0.50 Partially Correct | type = 2

Test #78:

score: 5
Acceptable Answer
time: 35ms
memory: 78008kb

input:

1000
100 2700 2
30 1
80 16
38 94
10 15
32 2
83 88
58 8
12 78
95 35
14 18
63 5
39 70
78 72
3 16
67 4
89 84
52 66
44 43
64 11
61 96
22 48
48 35
92 1
90 75
40 46
74 79
27 28
43 96
57 34
34 73
51 81
81 56
73 99
99 9
97 8
24 77
91 26
42 85
13 77
77 49
49 17
17 28
28 8
8 98
98 69
69 86
86 1
1 85
85 84
84 ...

output:

86 32 51 4 56 77 16 20 67 80 46 3 40 87 45 50 60 100 6 55 82 68 71 15 10 94 31 38 59 75 23 90 96 47 61 78 43 44 12 11 72 54 64 79 26 19 74 91 88 41 83 36 9 65 37 5 89 63 7 62 24 35 14 48 22 18 13 95 17 49 76 28 73 27 34 57 8 99 58 81 97 66 69 52 98 53 93 84 29 42 21 85 70 92 39 30 25 1 33 2 
65 90 2...

result:

points 0.50 Partially Correct | type = 2

Test #79:

score: 5
Acceptable Answer
time: 43ms
memory: 78240kb

input:

500
181 10132 2
63 62
111 83
175 78
89 149
163 95
54 2
165 55
55 119
162 58
131 86
4 8
41 71
15 47
130 20
10 42
35 141
146 166
14 135
181 176
42 7
68 128
51 116
16 64
160 171
38 21
90 25
168 20
100 50
177 132
65 138
43 147
25 164
115 127
27 22
58 21
7 150
44 144
12 141
124 173
102 109
29 153
32 112
...

output:

175 97 90 139 111 94 83 37 41 129 71 12 150 35 7 141 10 76 42 89 102 149 109 74 164 33 103 177 25 132 63 121 62 174 18 43 136 147 148 16 105 64 131 142 86 34 49 14 146 135 154 28 119 113 165 123 55 163 152 95 99 137 169 3 114 85 110 106 5 98 38 32 166 112 6 52 11 126 122 117 15 69 47 1 44 61 144 158...

result:

points 0.50 Partially Correct | type = 2

Test #80:

score: 5
Acceptable Answer
time: 41ms
memory: 78076kb

input:

200
471 12114 2
415 145
297 397
304 440
14 104
181 443
273 49
105 78
84 2
212 53
432 390
394 451
468 286
127 263
113 238
171 196
59 117
392 349
215 94
356 442
344 338
192 86
66 257
241 450
306 26
272 142
161 384
58 196
218 463
93 23
312 372
54 308
308 68
452 345
51 247
418 76
122 8
198 139
424 108
5...

output:

161 111 384 88 405 269 319 103 45 259 444 240 280 235 174 438 442 48 371 244 106 223 39 370 356 187 34 471 288 9 91 316 60 203 348 341 152 238 41 113 315 124 73 242 148 281 353 276 193 11 377 141 149 94 207 279 145 79 53 169 95 254 87 368 180 450 17 466 241 212 415 215 194 332 413 440 172 458 24 354...

result:

points 0.50 Partially Correct | type = 2

Test #81:

score: 10
Accepted
time: 47ms
memory: 78460kb

input:

100
975 217172 2
649 311
744 359
221 637
308 496
259 838
859 382
738 637
17 87
454 452
546 664
703 942
867 284
754 964
12 467
114 932
36 393
390 469
42 328
115 480
462 329
39 8
233 588
86 130
325 316
872 258
341 967
967 162
941 288
687 871
258 356
321 468
581 476
31 813
133 538
635 824
331 377
71 50...

output:

521 895 461 951 928 797 135 865 953 944 648 737 938 109 728 766 746 219 282 731 587 460 553 101 866 118 476 887 575 251 194 95 487 262 861 523 142 693 342 973 305 780 756 79 227 884 317 858 232 49 585 208 590 459 922 314 313 573 652 664 429 546 623 468 557 790 929 594 515 36 627 306 602 685 457 531 ...

result:

ok Accepted.

Test #82:

score: 10
Accepted
time: 44ms
memory: 78436kb

input:

50
1867 423383 1
1402 1596
1768 1660
84 1611
368 1781
53 1341
996 1046
806 1866
1460 742
1359 1004
1863 605
489 250
388 1318
135 845
392 346
1257 855
654 77
490 640
1808 1148
384 614
1495 275
1196 1236
827 75
75 1712
254 726
1436 1432
1344 1476
728 739
1016 523
523 1837
381 1623
1703 1397
59 1827
52...

output:

836 959 571 1153 1464 1707 265 707 1516 1693 1553 1867 182 1230 154 528 211 259 479 267 1273 1825 1346 1836 1137 809 1234 411 205 912 1315 444 540 432 1360 300 291 1466 835 1756 292 306 1260 1404 500 202 1811 1020 797 522 1421 1319 1682 877 673 1146 1749 1759 1109 1143 6 187 1849 1353 1571 329 641 3...

result:

ok Accepted.

Subtask #9:

score: 11
Acceptable Answer

Dependency #1:

100%
Accepted

Dependency #2:

50%
Acceptable Answer

Dependency #3:

50%
Acceptable Answer

Dependency #4:

50%
Acceptable Answer

Dependency #5:

50%
Acceptable Answer

Dependency #6:

50%
Acceptable Answer

Dependency #7:

50%
Acceptable Answer

Dependency #8:

50%
Acceptable Answer

Test #83:

score: 11
Acceptable Answer
time: 51ms
memory: 77952kb

input:

500000
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2
1 0 2
1 0 2
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 2
1 0 1
1 0 1
1 0 2
1 0 1
1 0 1
1 0 2
1 0 2...

output:

1 
1 
-1
-1
1 
1 
1 
-1
1 
1 
1 
1 
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
-1
-1
1 
-1
-1
1 
1 
-1
-1
-1
1 
1 
1 
-1
1 
1 
-1
1 
-1
1 
-1
-1
-1
1 
1 
1 
1 
1 
1 
-1
-1
-1
1 
1 
1 
1 
-1
1 
1 
-1
-1
-1
1 
-1
-1
-1
1 
1 
1 
-1
1 
1 
-1
1 
-1
-1
1 
1 
...

result:

points 0.50 Partially Correct | type = 2

Test #84:

score: 22
Accepted
time: 186ms
memory: 79276kb

input:

100
4914 5868584 2
4855 1980
1713 1299
1733 640
3936 2505
1258 1919
2989 2100
1549 1808
3837 534
2254 2130
459 1376
3914 200
2187 692
3465 2689
4501 1594
4516 3783
4095 3045
22 2133
1256 1369
1073 1136
646 3990
4506 3499
2663 3812
3649 3512
3573 2111
2241 2707
1879 2677
4216 2691
2878 1285
4604 4816...

output:

2701 2850 1360 3853 4452 3997 1151 3365 3474 1408 4281 4810 972 1592 1825 2176 769 608 1558 62 323 575 1102 946 1572 1456 3337 1838 844 1559 2006 1079 1186 3300 579 3548 3519 2349 1683 4581 3198 3545 3051 473 2989 4498 2100 2604 4440 2432 1250 2157 1028 2143 3447 3752 291 2277 4000 3364 2221 1799 86...

result:

ok Accepted.

Test #85:

score: 22
Accepted
time: 204ms
memory: 80748kb

input:

50
9264 14343522 2
4127 3748
8726 7859
1654 448
5251 8559
2277 3834
8033 4427
8913 6115
759 3415
671 312
1678 2639
6702 2797
3520 7485
464 1726
2509 6969
3491 6541
1904 4841
443 3242
6363 7280
2589 1882
2697 5015
9186 9026
125 70
2312 5699
5927 4834
4402 4396
7256 8408
2441 5044
1999 3156
564 3901
2...

output:

4623 1117 5127 3435 5338 6494 8660 5946 709 7851 7931 3376 3243 7848 4156 799 4154 4288 1560 3619 3452 4959 6342 5861 4613 3485 4727 4140 8639 3546 6183 3629 4412 7117 1934 3160 6318 2101 7173 8425 2611 6800 5017 3101 1933 5274 4813 5437 2398 4487 3299 8287 4256 4728 1394 7905 8714 1950 3283 2983 45...

result:

ok Accepted.

Test #86:

score: 22
Accepted
time: 227ms
memory: 80540kb

input:

50
9392 58225 1
6228 6729
316 3831
4383 827
4783 206
901 8057
8725 8920
6509 5267
2014 6918
7013 8718
699 1492
7298 8293
309 3846
5194 5883
3758 6754
7087 2643
2026 4947
7467 4209
5897 1024
7167 8508
4305 2042
6807 9031
2272 3612
7696 4195
3339 8474
8564 1256
8979 1773
3222 4076
4412 8107
27 3558
23...

output:

8322 9342 7854 9128 8354 5949 6231 5484 8432 7057 7574 4307 8079 6252 2640 3181 9280 886 3434 3292 7444 4853 8502 7445 9312 7842 7488 9326 9194 7535 6853 8266 8948 7610 7937 4300 7684 5047 3334 5697 5585 9223 5226 3586 4421 8861 4332 1656 2013 3338 8323 162 9392 2763 653 7773 1569 1311 2154 2570 741...

result:

ok Accepted.

Test #87:

score: 22
Accepted
time: 256ms
memory: 83184kb

input:

25
19790 20927306 2
4444 6276
14933 10108
6231 5388
15299 4203
17068 12794
10252 8287
6787 4058
2947 7053
16913 8475
5104 4109
10834 9443
11748 12927
8388 16660
4325 9605
16413 2446
16668 323
2038 4364
19597 2386
17857 2971
12045 2107
10345 15034
5324 4685
1910 9248
19068 3915
8777 3401
17337 2365
1...

output:

2625 7662 16665 12017 1090 5413 11725 2228 3545 7263 10115 15653 15845 18009 13802 9762 5620 7181 8646 11201 2439 6101 13121 8586 13348 15160 9348 5904 6250 5681 19538 15900 19766 666 2476 6941 16578 8701 18962 1949 2759 5451 7005 13616 18176 9569 18301 13283 14658 6965 9247 16092 10356 8356 11699 1...

result:

ok Accepted.

Test #88:

score: 11
Acceptable Answer
time: 261ms
memory: 82876kb

input:

25
19975 93145930 2
12432 1834
1881 14484
15930 10534
10845 7335
8074 9798
361 16500
1801 6929
4437 3207
14447 5118
6677 4193
1052 4088
869 640
15256 8605
8186 18363
15464 3806
5778 17272
9822 14677
5350 15754
1674 18160
1783 8216
15853 14470
14582 12437
2545 812
1606 18202
19624 9375
1895 6171
8629...

output:

3605 2481 5285 17514 2182 17609 19959 18439 16438 3641 8393 10929 6709 16169 18436 17427 8126 8414 11733 4125 4374 11381 12419 18794 13633 388 2640 13068 5399 9499 19709 17547 13386 11769 19023 2596 19079 10581 13882 4851 12367 1179 11948 6990 620 15756 13262 10426 7145 19301 11566 10913 18184 5099 ...

result:

points 0.50 Partially Correct | type = 2

Test #89:

score: 22
Accepted
time: 335ms
memory: 89796kb

input:

10
47976 591885312 2
5124 43680
2252 9516
19288 8740
28470 38971
44005 16449
35113 31009
7142 23054
26551 47176
10450 26089
21857 23087
41980 36670
42848 35489
10282 16403
5395 30470
15802 45845
17969 7447
34743 7617
34799 20623
34264 26807
33968 43764
29498 27833
40072 29805
28680 33112
22228 26794...

output:

30180 28670 21788 46675 13059 17731 29854 19363 24225 2536 5703 8799 11688 24782 7511 26959 26937 967 19210 39749 2083 36679 39891 19948 37295 6911 39566 8739 30599 46578 38858 15256 26773 37781 43460 2792 12560 2133 19050 38363 1404 29915 37596 24572 14849 34109 14332 15738 14633 6711 11183 22796 3...

result:

ok Accepted.

Test #90:

score: 22
Accepted
time: 295ms
memory: 89860kb

input:

10
45442 215847028 1
18473 30982
44534 41274
2723 45201
13119 6426
38639 43918
31640 2906
32096 15308
1356 8922
22081 4880
45055 5993
13173 20550
16941 19759
16629 2018
19954 43873
13002 18173
11394 28098
41851 25383
5142 31705
27108 15842
35992 22440
32300 24908
6264 14876
8386 39768
27107 20226
11...

output:

32473 36285 14436 31928 33683 8734 41765 17873 34877 9577 28287 9626 38345 33774 40415 44443 29886 17232 24699 32129 20204 24232 29365 41306 10304 4472 25482 42527 16037 7240 23417 44182 31703 22910 23953 24625 7354 20539 29154 11670 20591 27228 10336 17161 26923 4767 3151 3617 747 42258 37271 20882...

result:

ok Accepted.

Test #91:

score: 22
Accepted
time: 363ms
memory: 100968kb

input:

5
98026 412627902 2
48046 18927
13901 28466
35521 5201
80007 11667
80793 96581
55539 20025
5543 85851
55543 21411
29340 34851
29610 60263
18792 84130
32073 75581
78498 30643
1376 11678
50702 79538
3515 33613
58947 90914
32141 54510
97107 57425
16944 15325
26833 50683
53820 39405
4095 9382
40911 6943...

output:

44516 12305 37076 29177 37207 93044 68285 2382 42127 64084 82517 67973 34122 22907 61473 17607 57493 23711 7556 28366 45104 1326 95611 43607 57939 54605 58337 89431 19577 86147 96040 46948 31956 40399 42661 31420 77329 63651 77593 53380 24134 37116 26538 28382 82441 75744 85533 39300 46841 11952 538...

result:

ok Accepted.

Test #92:

score: 22
Accepted
time: 428ms
memory: 101376kb

input:

5
91305 1628174951 1
56198 20850
52916 85909
35476 56437
1834 9115
12192 10250
42982 57176
9593 27306
24150 48020
65107 42644
78643 42705
52340 56849
10078 23282
57269 5876
77632 26605
32767 24018
81204 21219
47096 12948
33055 2485
54922 15109
4406 72601
71077 36886
57706 24314
9215 42336
36145 6145...

output:

3352 303 46024 53857 78103 42037 2594 3703 76087 23410 70607 80403 23667 284 40852 11719 84165 16756 37647 13360 46750 35107 29853 15920 13672 5016 54595 83481 56176 88748 67836 49013 87736 219 83718 86390 58373 9384 60250 81318 55603 15999 74711 25597 35262 78298 20701 3585 27313 68646 24566 4422 5...

result:

ok Accepted.

Test #93:

score: 22
Accepted
time: 923ms
memory: 185696kb

input:

1
472025 16043466085 1
417926 39623
195768 229314
370537 57531
267104 382113
170933 141578
53561 74294
250159 31886
9352 36181
322148 394068
117039 351210
300887 304015
24549 24940
114489 128610
411952 339863
71691 11387
73530 4523
10760 14371
149252 155462
22680 357719
350109 402379
152082 101050
2...

output:

388726 288748 191104 323804 407504 180816 215261 390401 81823 198616 116420 72698 4200 241819 304949 139240 141852 417332 469755 435816 308316 307505 43000 103734 90895 144260 322531 249397 93118 64448 200169 252630 242932 270468 445488 361251 215056 123904 468996 154324 381459 330410 93365 99195 89...

result:

ok Accepted.

Test #94:

score: 11
Acceptable Answer
time: 132ms
memory: 78036kb

input:

62500
8 19 1
8 1
2 3
7 3
3 6
6 4
4 1
1 5
8 14 2
3 2
8 2
1 4
4 5
5 6
6 2
2 7
8 20 1
2 1
4 7
7 3
3 6
6 8
8 1
1 5
8 10 1
1 3
8 6
6 3
3 4
4 7
7 5
5 2
8 11 1
5 6
6 1
1 8
8 3
3 4
4 2
2 7
8 14 2
6 1
2 4
4 1
1 8
8 3
3 5
5 7
8 14 1
8 6
3 5
5 7
7 4
4 6
6 1
1 2
8 15 1
4 3
1 6
8 6
6 3
3 2
2 5
5 7
8 22 2
4 7
6 3...

output:

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

result:

points 0.50 Partially Correct | type = 2

Test #95:

score: 22
Accepted
time: 1063ms
memory: 183940kb

input:

1
482724 69862381824 1
137472 24627
53394 136713
29923 24872
183115 104962
360179 53778
95044 16923
208793 216766
343809 82383
389111 122728
267129 163660
381943 86337
191746 130719
179638 171500
16541 49248
9266 60892
245541 12470
324537 105560
368925 467572
480713 67654
10418 410596
140876 300727
...

output:

254546 478091 299458 132617 202943 362351 181682 4466 312496 168155 178132 93440 135382 248622 32801 132551 182371 57456 151219 153108 333937 287365 227892 386262 80154 107612 147683 107156 248302 251428 202572 243788 179933 217110 384652 469350 443140 109076 427864 218480 208422 234967 323250 22104...

result:

ok Accepted.

Test #96:

score: 22
Accepted
time: 930ms
memory: 181308kb

input:

1
466556 37068012357 1
296077 254374
55895 139417
250053 262476
281210 151748
361746 75307
38308 211
25635 226913
290473 170308
112117 207274
333222 333380
165721 128597
76733 301893
137129 112197
171945 20656
193257 43287
93646 249912
343755 80957
434796 359970
277965 34924
188290 4117
401431 43469...

output:

220891 137345 187112 31855 394761 370949 46406 126880 359441 353112 255175 278656 158120 356357 402115 459254 78370 119907 122925 345077 394182 298746 133227 259341 279669 361343 330595 334783 296285 145828 455522 184267 297476 298261 198485 337747 128183 127543 226557 391241 157057 207664 361289 12...

result:

ok Accepted.

Test #97:

score: 22
Accepted
time: 924ms
memory: 183184kb

input:

1
470507 15553613111 1
116590 375013
25458 460568
274726 423221
185476 26173
129323 115569
393959 379177
186613 320883
413505 47092
298840 72519
445171 170296
28563 18974
198881 343336
153370 1813
428633 372899
188361 262767
97460 411511
23648 449045
388428 367955
10793 398742
305885 3039
441903 422...

output:

144970 318449 194266 344458 355472 114270 459866 259165 288909 33510 58040 552 401419 292139 338381 154122 296905 461455 22808 150276 310129 242890 414459 343772 16968 68455 237931 287250 293968 342242 338444 168726 320144 302222 187413 86865 82863 156768 421062 257661 112025 33842 27093 10029 30348...

result:

ok Accepted.

Test #98:

score: 22
Accepted
time: 585ms
memory: 183160kb

input:

1
484644 70415722676 2
387061 60091
283751 60069
107460 354884
445876 55307
338664 281406
388782 24215
35572 117625
177669 98530
7682 233035
116725 414416
355609 95819
475062 198221
241991 472832
44124 13983
140233 377622
213795 216775
272564 443204
119914 351907
326597 142211
466195 381175
457028 2...

output:

43836 167291 410656 144940 466315 152424 198707 399045 44743 233991 452550 396506 127875 222641 65199 13760 101729 318837 188181 31879 27976 149496 197613 302528 280000 74453 3788 146903 394600 360729 233216 448499 190607 181374 261500 340869 437414 46908 307385 180776 446844 361858 282453 350210 25...

result:

ok Accepted.

Test #99:

score: 22
Accepted
time: 580ms
memory: 182380kb

input:

1
480049 66333578702 2
414780 52384
229954 204017
477598 350060
177290 395393
22600 399649
194443 4952
375752 445636
81605 302911
366288 84718
57315 335522
472784 367329
137447 408097
409021 236863
121965 347700
346918 58159
445793 183641
255068 367810
442172 237707
471652 352900
286081 25476
89138 ...

output:

402553 221494 173732 131261 26031 307691 64574 177397 257309 419990 75122 453650 149532 39733 396192 364127 267002 322772 134732 211392 432939 283214 207395 369461 22976 385480 390777 370067 26662 379576 421888 136313 445696 366591 408721 409519 402382 174084 102075 382120 386968 347771 309895 54052...

result:

ok Accepted.

Test #100:

score: 11
Acceptable Answer
time: 87ms
memory: 78124kb

input:

1000
498 181292 1
55 405
423 313
133 192
359 39
367 203
366 42
100 76
358 263
183 445
87 27
114 402
331 371
272 424
394 194
417 268
285 284
328 59
125 495
495 364
201 407
310 18
337 283
213 154
346 229
16 65
341 480
315 252
393 19
7 153
365 86
95 144
287 349
262 470
332 295
424 255
336 491
491 311
6...

output:

-1
349 176 424 206 17 228 56 21 34 253 73 406 417 16 223 303 192 287 18 410 214 365 31 171 198 102 48 374 312 475 152 244 430 367 25 316 106 232 337 300 272 23 274 433 468 340 163 47 285 45 352 233 358 448 364 219 329 363 318 213 75 147 313 142 453 292 326 227 13 124 412 126 43 76 308 22 438 24 8 11...

result:

points 0.50 Partially Correct | type = 2

Test #101:

score: 11
Acceptable Answer
time: 145ms
memory: 78300kb

input:

10000
45 550 2
44 17
41 23
36 17
38 11
35 13
5 30
24 26
1 9
25 16
16 40
13 18
26 37
32 7
7 17
39 2
27 12
12 34
34 15
15 30
30 14
14 18
18 37
37 20
20 9
9 29
29 28
28 8
8 3
3 23
23 19
19 6
6 17
17 10
10 2
2 40
40 21
21 33
33 11
11 45
45 4
4 22
22 43
43 42
42 31
46 635 1
1 9
27 4
26 25
19 23
44 11
18 ...

output:

35 6 7 32 27 36 41 44 23 17 3 8 28 10 2 39 29 16 9 1 20 40 25 37 18 21 24 33 26 38 13 11 14 45 5 4 22 30 43 15 31 34 42 12 19 
23 24 8 34 37 19 7 15 10 5 21 38 40 18 20 6 45 33 29 27 31 4 3 46 44 16 11 14 39 2 41 43 1 36 9 30 32 17 22 28 25 35 12 13 26 42 
42 36 33 20 41 1 4 10 19 17 27 34 28 12 48 ...

result:

points 0.50 Partially Correct | type = 2

Test #102:

score: 11
Acceptable Answer
time: 166ms
memory: 78052kb

input:

2000
230 11927 1
198 69
181 202
214 145
16 114
211 199
20 92
100 194
177 145
55 228
228 152
101 138
203 42
137 186
36 77
189 152
152 196
6 22
57 123
123 213
213 27
217 157
187 127
22 172
172 168
224 155
33 144
144 13
167 166
61 209
135 175
48 200
199 124
50 230
161 109
190 226
30 155
86 79
79 183
29...

output:

203 47 42 188 84 89 154 144 33 7 49 13 218 100 137 221 149 194 9 43 40 106 148 101 54 70 34 138 107 191 119 126 164 214 174 145 83 177 215 71 171 93 95 88 223 185 127 196 114 16 208 118 156 182 108 135 120 175 94 3 158 219 147 131 14 25 206 29 153 205 134 187 115 72 76 122 31 110 146 117 24 217 37 1...

result:

points 0.50 Partially Correct | type = 2

Test #103:

score: 11
Acceptable Answer
time: 172ms
memory: 78156kb

input:

1000
465 6312 1
172 465
369 274
119 226
243 432
107 307
438 450
462 86
210 147
283 27
463 112
75 236
452 25
381 451
366 131
92 121
394 111
241 400
317 67
85 161
254 13
153 277
251 83
295 398
145 261
165 219
311 454
66 399
272 445
387 236
120 10
37 273
216 181
464 439
108 298
214 253
441 234
186 234
...

output:

248 187 208 226 119 107 323 45 437 40 122 204 378 198 235 337 349 101 458 460 428 222 69 445 272 320 305 164 33 324 350 65 404 356 247 346 83 134 38 297 197 331 281 291 141 299 408 293 251 457 330 415 228 285 50 95 183 217 47 300 203 63 231 419 196 433 121 92 200 189 232 8 23 62 309 397 413 17 130 3...

result:

points 0.50 Partially Correct | type = 2

Test #104:

score: 11
Acceptable Answer
time: 173ms
memory: 78260kb

input:

500
975 3692 1
48 713
274 540
244 542
880 807
684 55
596 796
763 802
626 90
958 281
863 846
215 708
894 106
301 585
772 776
305 252
182 782
314 574
254 211
533 842
86 389
527 388
459 595
726 938
601 412
338 392
669 176
737 556
897 160
121 963
262 106
641 462
462 733
581 224
740 878
817 485
350 895
9...

output:

813 777 39 151 910 723 597 598 738 317 351 552 61 361 703 568 609 191 235 688 259 370 807 330 844 818 438 237 445 880 524 545 790 714 396 612 537 867 368 472 23 640 8 208 332 483 653 797 127 513 413 288 787 871 106 262 894 315 921 890 219 298 437 77 648 120 656 22 503 775 918 962 416 665 750 192 436...

result:

points 0.50 Partially Correct | type = 2

Test #105:

score: 11
Acceptable Answer
time: 177ms
memory: 78264kb

input:

500
962 55094 2
235 718
135 459
342 659
434 460
921 812
495 217
751 340
546 326
439 820
337 780
523 223
658 277
938 947
701 493
809 501
198 895
883 554
293 504
627 939
103 688
297 215
26 828
3 402
273 885
190 172
470 871
465 889
244 698
356 926
878 940
23 961
730 476
906 459
80 479
823 139
881 395
3...

output:

787 788 325 923 898 649 293 662 329 177 670 423 40 474 655 193 940 120 878 778 95 884 558 335 9 102 867 609 761 283 72 27 288 331 837 63 849 469 951 349 452 149 333 907 576 786 689 910 249 282 700 919 200 669 560 834 261 870 857 673 806 225 92 194 880 587 541 775 628 698 554 353 229 244 820 439 564 ...

result:

points 0.50 Partially Correct | type = 2

Test #106:

score: 11
Acceptable Answer
time: 167ms
memory: 79284kb

input:

100
4746 1051132 2
1237 3867
2107 4075
3048 3224
2208 1419
3875 1498
598 1118
4554 3504
1732 1316
1594 1279
3626 2781
2662 3766
3719 4529
4566 3799
178 2964
340 768
2823 3777
217 2269
2504 2945
345 4068
2882 3668
2116 471
2368 3872
606 1614
2884 961
1854 4389
4510 920
3424 2284
3637 2875
1692 2741
1...

output:

2843 421 4685 3545 4689 1592 3694 1819 3631 3911 812 4318 2460 2528 3953 2909 3592 238 607 1486 1829 3587 2341 4140 3188 2387 2599 636 1815 3415 203 678 638 4074 3755 1426 3459 32 279 3031 415 1298 1885 3330 3470 1231 3765 1269 1303 726 1142 2991 4454 1262 1447 3045 1686 2285 1433 594 2584 2396 3281...

result:

points 0.50 Partially Correct | type = 2

Test #107:

score: 11
Acceptable Answer
time: 194ms
memory: 79512kb

input:

100
4503 2286264 1
1641 2688
3396 2617
2562 833
1305 2310
638 850
2450 2086
1235 1661
4143 1757
3412 3937
1584 12
1159 736
3175 3109
1202 2747
3778 3893
1592 1029
203 982
3709 1326
2540 2325
2707 893
43 2008
2203 2422
1901 3772
559 3365
4355 2942
1770 3316
2864 2218
2544 359
763 4500
3537 2236
376 2...

output:

3710 1677 3419 2069 83 3639 3070 1045 574 4211 309 1805 2444 1209 4310 2300 2700 2218 950 787 3549 2864 3765 2206 158 4057 922 3531 1611 4350 2916 3047 2571 1647 4264 4347 3282 1821 1999 2380 3143 3901 2097 4296 2047 1851 1638 1662 2418 2157 56 1193 3373 24 360 37 4388 4459 753 890 395 1258 3578 445...

result:

points 0.50 Partially Correct | type = 2