QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#374487#7410. Apollonian Networkbear0131AC ✓541ms73428kbC++148.2kb2024-04-02 14:37:402024-04-02 14:37:40

Judging History

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

  • [2024-04-02 14:37:40]
  • 评测
  • 测评结果:AC
  • 用时:541ms
  • 内存:73428kb
  • [2024-04-02 14:37:40]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 1e9 + 7;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, ll p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 66666;
int fact[fN], invfact[fN], inv[fN];
void initfact(int n){
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
	for(int i = 1; i <= n; ++i) inv[i] = mul(invfact[i], fact[i-1]);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }
inline void chmin(int &a, int b){ (b<a) ? (a=b) : 0; }
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
inline void chmin(ll &a, ll b){ (b<a) ? (a=b) : 0; }

int n, w[255][255], cid[255][255][255], cc = 0;
array<int, 3> cs[1010];
vi to[1010];
int rt, fa[1010];
int dp[1010][2][2][2][111];

int outmp[66666];

void dfs0(int id){
	//cout << "dfs0 " << id << " " << fa[id] << "\n";
	array<int, 3> c = cs[id];
	for(auto u : to[id]){
		if(u == fa[id]) continue;
		int t;
		t = cid[c[0]][c[1]][u], fa[t] = c[2], dfs0(t);
		t = cid[c[1]][c[2]][u], fa[t] = c[0], dfs0(t);
		t = cid[c[2]][c[0]][u], fa[t] = c[1], dfs0(t);
	}
}

const int outp[4] = {0, 1, 2, 7}, outq[8] = {0, 1, 2, -1, -1, -1, -1, 3};

int getdp(int id, array<int, 3> tp, int outs){
	int DEBUG = 0;//(id == 12 && outs == 0);//(id == 12 && outs == 16384);
	if(DEBUG){
		cout << "------------------getdp " << id << " {" << tp[0] << " " << tp[1] << " " << tp[2] << "} " << outs << "-------------------------" << "\n";
		cout << cs[id][0] << " " << cs[id][1] << " " << cs[id][2] << "\n";
		rep(i, 4) rep(j, 4) if((outs>>(i*4+j)) & 1){ cout << i << " " << j << "\n"; }
	}
	int outid = outmp[outs];
	int &ans = dp[id][tp[0]][tp[1]][tp[2]][outid];
	if(ans != -1) return ans;
	ans = -inf;

	vi ps(3);
	rep(i, 3) ps[i] = cs[id][i];
	int m = -1;
	for(auto v : to[id]){
		if(v == fa[id]) continue;
		m = v;
		ps.push_back(m);
	}

	if(m < 0) return ans = -inf;

	int cn = 8;
	array< array<int, 8>, 8 > has, done, ew;
	rep(i, cn) rep(j, cn) has[i][j] = done[i][j] = ew[i][j] = 0;
	auto ae = [&](int u, int v, bool hasw = 0){
		if(DEBUG) cout << "ae " << u << " " << v << "\n";
		has[u][v] = has[v][u] = 1;
		if(hasw) ew[u][v] = ew[v][u] = w[ps[u]][ps[v]];
	};
	if(id == rt){
		ae(0, 1, 1), ae(1, 2, 1), ae(2, 0, 1);
	}
	if(m >= 0){
		ae(0, 3, 1), ae(1, 3, 1), ae(2, 3, 1), ae(7, 3);
		ae(0, 4), ae(1, 4), ae(3, 4), ae(7, 4);
		ae(1, 5), ae(2, 5), ae(3, 5), ae(7, 5);
		ae(2, 6), ae(0, 6), ae(3, 6), ae(7, 6);
	}

	rep(i, 4) rep(j, 4){
		if((outs>>(i*4+j)) & 1){
			has[outp[i]][outp[j]] = 1;
			if(i == 3) rep(k, 7) if(k != j) has[7][k] = 0;
			if(j == 3) rep(k, 7) if(k != i) has[k][7] = 0;
		}
	}

	if(DEBUG){
		rep(i, 8){
			rep(j, 8) cout << has[i][j] << " ";
			cout << "\n";
		}
	}

	vi pth;
	auto check = [&](){
		int ok = 1;
		rep(i, 4){
			rep(j, 4){
				if((outs>>(i*4+j)) & 1){
					if(!done[outp[i]][outp[j]]){
						ok = 0;
						break;
					}
				}
			}
			if(!ok) break;
		}
		if(!ok) return ;
		int val = 0;
		array<int, 8> lstout;
		rep(i, 8) lstout[i] = -1;
		array< vector<pii>, 8 > es;
		rep(i, 8) es[i].clear();
		rep(i, (int)pth.size() - 1){
			int u = pth[i], v = pth[i+1];
			if(u <= 3 && v <= 3){
				val += ew[u][v];
			}
			if(v >= 4 && v <= 6){
				if(lstout[v] < 0)
					es[v].push_back(make_pair(7, u));
				else 
					es[v].push_back(make_pair(lstout[v], u));
			}
			lstout[u] = v;
		}
		//DEBUG = 0;//((id == 12 && outs == 16384) && pth == (vi){7, 2, 3, 4, 0, 1, 4, 7});
		if(DEBUG){
			for(auto u : pth) cout << u << ", ";
			cout << "\n";
		}
		for(int i = 4; i <= 6; ++i){
			if(es[i].empty()) continue;
			es[i].push_back(make_pair(lstout[i], 7));

			int nid = cid[ps[i-4]][ps[(i-4+1)%3]][ps[3]];

			static int can[255], mp[255];
			rep(j, 3) mp[cs[nid][j]] = j;
			rep(j, 4) can[ps[j]] = (done[i][j] || done[j][i]);
			array<int, 3> ntp;
			rep(j, 3) ntp[j] = can[cs[nid][j]];
			
			int nmask = 0;
			for(auto p : es[i]){
				if(p.first == p.second) continue;
				//cout << p.first << " to " << p.second << "\n";
				nmask |= 1 << (outq[p.first == 7 ? 7 : mp[ps[p.first]]] * 4 + outq[p.second == 7 ? 7 : mp[ps[p.second]]]);
			}
			val += getdp(nid, ntp, nmask);
			//if(val == 5570866) cout << "from " << i << " " << tmptmp << endl;
			if(val < 0){ val = -inf; break; }
		}
		//if(val == 5570866 || val == 5570866 - 1652412){
		//	cout << "------------------getdp " << id << " {" << tp[0] << " " << tp[1] << " " << tp[2] << "} " << outs << "-------------------------" << "\n";
		//	cout << cs[id][0] << " " << cs[id][1] << " " << cs[id][2] << "\n";
		//	rep(i, 4) rep(j, 4) if((outs>>(i*4+j)) & 1){ cout << i << " " << j << "\n"; }
		//	for(auto u : pth) cout << u << ", ";
		//	cout << "\n";
		//}
		chmax(ans, val);
	};

	array<int, 8> vis;
	rep(i, 8) vis[i] = 0;
	function<void(int)> dfs = [&](int u){
		++vis[u], pth.push_back(u);
		if((int)pth.size() > 1 && u == 7){
			check();
			--vis[u], pth.pop_back();
			return ;
		}
		rep(t, cn) if(has[u][t]){
			//if(DEBUG) cout << " dfs " << u << " to " << t << "\n";
			if(done[u][t] || (t < 3 && tp[t] == 0) || (t <= 3 && vis[t])) continue;
			done[u][t] = 1;
			dfs(t);
			done[u][t] = 0;
		}
		--vis[u], pth.pop_back();
	};

	dfs(7);

	return ans;
}

int main(){
	//freopen("d.in", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	memset(w, 0x3f, sizeof(w));
	rep(i, 3*(n-2)){
		int u, v, c;
		cin >> u >> v >> c;
		--u, --v;
		w[u][v] = w[v][u] = c;
	}

	if(n == 3){
		cout << w[0][1] + w[1][2] + w[2][0] - min({w[0][1], w[1][2], w[2][0]}) << "\n";
		return 0;
	}

	memset(cid, -1, sizeof(cid));
	rep(i, n) rep(j, i) if(w[i][j] < inf) rep(k, j) if(w[j][k] < inf && w[k][i] < inf){
		cs[cc] = {k, j, i};
		cid[i][j][k] = cid[i][k][j] = cid[j][i][k] = cid[j][k][i] = cid[k][i][j] = cid[k][j][i] = cc++;
	}

	rt = 0;
	rep(i, cc){
		array<int, 3> c = cs[i];
		rep(u, n) if(cid[c[0]][c[1]][u] >= 0 && cid[c[1]][c[2]][u] >= 0 && cid[c[2]][c[0]][u] >= 0) to[i].push_back(u);
		if((int)to[i].size() == 1) rt = i;
	}

	//rep(i, n) rep(j, n) rep(k, n) cout << i << " " << j << " " << k << ": " << cid[i][j][k] << "\n";

	//rep(i, cc) cout << i << ": " << cs[i][0] << " " << cs[i][1] << " " << cs[i][2] << "\n";
	//rep(i, cc){
	//	cout << cs[i][0] << cs[i][1] << cs[i][2] << " " << i << " to ";
	//	for(auto u : to[i]) cout << u << " ";
	//	cout << "\n";
	//}
	//cout << rt << "\n";

	fa[rt] = -1, dfs0(rt);

	memset(dp, -1, sizeof(dp));

	int co = 0;
	rep(mask, 1<<16){
		array< array<int, 4>, 4 > has;
		rep(i, 4) rep(j, 4) has[i][j] = (mask>>(i*4+j)) & 1;
		bool ok = 1;
		rep(i, 4) if(has[i][i]) ok = 0;
		rep(i, 4){
			int cnt = 0;
			rep(j, 4) cnt += has[i][j];
			if(cnt > 1) ok = 0;
		}
		rep(i, 4){
			int cnt = 0;
			rep(j, 4) cnt += has[j][i];
			if(cnt > 1) ok = 0;
		}
		if(ok) outmp[mask] = co++;
	}

	//cout << co << "\n";
	
	int ans = getdp(rt, {1, 1, 1}, 0);
	rep(i, 3) chmax(ans, getdp(rt, {1, 1, 1}, 1 << (i*4 + 3)));
	rep(j, 3) chmax(ans, getdp(rt, {1, 1, 1}, 1 << (3*4 + j)));
	rep(i, 3) rep(j, 3)
		chmax(ans, getdp(rt, {1, 1, 1}, (1 << (i*4 + 3)) + (1 << (3*4 + j))));
	cout << ans << "\n";

	cerr << 1. * clock() / CLOCKS_PER_SEC << endl;

	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5848kb

input:

3
1 2 1
2 3 1
3 1 2

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 15ms
memory: 72464kb

input:

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

output:

35

result:

ok 1 number(s): "35"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7748kb

input:

3
1 2 0
3 2 1
3 1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7780kb

input:

3
3 2 123
2 1 67
3 1 763

output:

886

result:

ok 1 number(s): "886"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7940kb

input:

3
3 2 724482
2 1 326757
3 1 386076

output:

1110558

result:

ok 1 number(s): "1110558"

Test #6:

score: 0
Accepted
time: 0ms
memory: 72428kb

input:

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

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 3ms
memory: 72532kb

input:

4
3 4 831
4 2 412
3 2 641
1 3 756
1 4 909
2 1 254

output:

2381

result:

ok 1 number(s): "2381"

Test #8:

score: 0
Accepted
time: 3ms
memory: 72940kb

input:

4
2 4 381962
4 3 793293
2 3 408508
2 1 425132
1 4 774548
3 1 430802

output:

1992973

result:

ok 1 number(s): "1992973"

Test #9:

score: 0
Accepted
time: 7ms
memory: 72456kb

input:

5
2 5 1
3 5 1
2 3 1
4 2 1
4 5 1
3 4 0
1 2 1
4 1 0
1 3 0

output:

4

result:

ok 1 number(s): "4"

Test #10:

score: 0
Accepted
time: 3ms
memory: 73036kb

input:

5
2 5 595
5 4 813
4 2 828
2 1 852
5 1 959
1 4 816
3 2 112
3 1 252
3 4 424

output:

3063

result:

ok 1 number(s): "3063"

Test #11:

score: 0
Accepted
time: 3ms
memory: 72472kb

input:

5
4 3 200019
2 4 422357
3 2 853305
3 1 371136
4 1 358800
2 1 889385
3 5 390874
1 5 239492
4 5 317497

output:

2492364

result:

ok 1 number(s): "2492364"

Test #12:

score: 0
Accepted
time: 8ms
memory: 72704kb

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #13:

score: 0
Accepted
time: 14ms
memory: 72732kb

input:

6
1 4 735
3 4 627
3 1 442
2 1 496
2 4 325
3 2 836
1 5 637
5 2 53
3 5 32
6 2 684
5 6 448
3 6 113

output:

3519

result:

ok 1 number(s): "3519"

Test #14:

score: 0
Accepted
time: 8ms
memory: 72704kb

input:

6
4 3 205961
5 4 30950
5 3 65968
2 3 303988
2 4 184729
2 5 843062
4 6 481378
6 2 664463
5 6 545405
1 3 383865
2 1 307891
4 1 669247

output:

3042015

result:

ok 1 number(s): "3042015"

Test #15:

score: 0
Accepted
time: 7ms
memory: 72492kb

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #16:

score: 0
Accepted
time: 15ms
memory: 72500kb

input:

7
6 5 862
6 4 299
4 5 584
5 2 737
6 2 957
2 4 407
7 6 260
2 7 857
7 4 631
2 3 701
3 7 361
3 4 541
1 5 283
2 1 228
1 6 163

output:

4131

result:

ok 1 number(s): "4131"

Test #17:

score: 0
Accepted
time: 13ms
memory: 72660kb

input:

7
5 2 459322
6 5 427540
6 2 187367
2 4 961056
5 4 103338
4 6 983153
2 1 771767
1 4 580227
6 1 371949
5 3 623838
4 3 208838
3 6 578640
4 7 222571
1 7 669259
7 6 53303

output:

4587713

result:

ok 1 number(s): "4587713"

Test #18:

score: 0
Accepted
time: 15ms
memory: 72624kb

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #19:

score: 0
Accepted
time: 16ms
memory: 72560kb

input:

8
3 7 367
6 7 119
6 3 702
1 3 769
1 7 948
6 1 515
7 8 96
1 8 55
6 8 642
5 7 564
5 8 195
5 1 54
4 7 934
4 5 641
4 1 671
1 2 186
8 2 70
6 2 325

output:

4706

result:

ok 1 number(s): "4706"

Test #20:

score: 0
Accepted
time: 8ms
memory: 72564kb

input:

8
7 3 728075
1 3 669805
1 7 908111
7 2 901659
2 3 127509
2 1 48044
8 7 287910
2 8 584282
8 3 292959
6 2 641410
8 6 979321
6 3 136905
7 4 212548
2 4 489178
4 1 379769
7 5 350931
5 4 21571
1 5 597009

output:

4636063

result:

ok 1 number(s): "4636063"

Test #21:

score: 0
Accepted
time: 13ms
memory: 72416kb

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #22:

score: 0
Accepted
time: 16ms
memory: 72540kb

input:

9
8 7 159
2 7 324
8 2 134
8 5 469
7 5 329
5 2 259
1 7 670
5 1 765
1 2 740
8 3 116
5 3 527
3 2 723
8 9 956
9 5 604
9 7 872
5 4 124
3 4 340
4 2 86
8 6 984
3 6 926
5 6 201

output:

6090

result:

ok 1 number(s): "6090"

Test #23:

score: 0
Accepted
time: 20ms
memory: 72428kb

input:

9
2 9 1776
8 2 965915
9 8 637994
5 9 391975
5 2 576116
5 8 303357
7 9 805273
5 7 721534
8 7 639873
9 3 249910
7 3 376286
3 5 819176
9 4 773174
4 3 172900
7 4 185855
6 9 268943
6 5 9090
2 6 187666
1 3 745755
1 4 911957
1 7 476567

output:

5848789

result:

ok 1 number(s): "5848789"

Test #24:

score: 0
Accepted
time: 17ms
memory: 72700kb

input:

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

output:

9

result:

ok 1 number(s): "9"

Test #25:

score: 0
Accepted
time: 22ms
memory: 72536kb

input:

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

output:

8

result:

ok 1 number(s): "8"

Test #26:

score: 0
Accepted
time: 19ms
memory: 72560kb

input:

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

output:

7

result:

ok 1 number(s): "7"

Test #27:

score: 0
Accepted
time: 14ms
memory: 72744kb

input:

10
5 8 771
9 5 728
9 8 240
2 8 815
2 5 118
9 2 988
10 8 513
2 10 949
10 5 513
6 8 746
6 2 478
9 6 332
7 5 754
7 2 817
9 7 354
2 4 196
10 4 904
5 4 794
8 1 153
10 1 339
1 5 410
3 8 256
10 3 155
2 3 770

output:

5930

result:

ok 1 number(s): "5930"

Test #28:

score: 0
Accepted
time: 15ms
memory: 73096kb

input:

10
7 2 535
4 2 494
7 4 642
3 7 446
2 3 339
3 4 949
1 7 644
1 3 810
1 2 466
8 7 42
8 1 297
8 2 118
9 7 947
8 9 647
2 9 855
7 10 758
8 10 193
10 1 56
5 8 185
10 5 699
5 1 483
7 6 593
6 1 415
3 6 553

output:

6288

result:

ok 1 number(s): "6288"

Test #29:

score: 0
Accepted
time: 16ms
memory: 72904kb

input:

10
3 8 760
3 10 881
10 8 600
7 8 732
3 7 773
10 7 567
9 3 192
9 7 798
9 10 427
3 6 38
9 6 562
10 6 757
4 9 325
6 4 748
4 10 427
5 6 883
5 4 532
5 10 90
1 4 618
5 1 447
1 10 117
4 2 989
2 1 923
10 2 578

output:

7255

result:

ok 1 number(s): "7255"

Test #30:

score: 0
Accepted
time: 18ms
memory: 72524kb

input:

10
9 3 532820
7 9 884172
3 7 990335
1 3 674226
1 9 748597
1 7 720815
3 2 852207
1 2 360164
9 2 939116
8 3 967366
1 8 714210
7 8 408588
9 10 789199
1 10 242778
10 7 442389
3 5 790845
5 2 622752
5 1 116990
3 4 904891
2 4 469074
9 4 646557
6 1 28022
6 2 348749
9 6 363364

output:

6100738

result:

ok 1 number(s): "6100738"

Test #31:

score: 0
Accepted
time: 18ms
memory: 72648kb

input:

10
1 5 91842
5 10 353811
10 1 62948
2 1 198100
2 5 513247
10 2 916235
4 1 783495
4 2 162627
5 4 778519
2 6 332497
6 4 592563
5 6 250810
3 1 392794
4 3 782688
3 5 722
7 2 123632
7 6 49788
4 7 765664
8 2 771323
7 8 937893
8 4 407488
9 5 772069
9 2 228947
10 9 514461

output:

6104744

result:

ok 1 number(s): "6104744"

Test #32:

score: 0
Accepted
time: 16ms
memory: 72592kb

input:

10
7 5 369618
5 2 111605
2 7 560430
7 1 53231
1 5 597492
2 1 656016
8 5 236755
1 8 146229
8 2 55028
1 3 955478
8 3 425707
2 3 342498
8 10 975337
3 10 483824
2 10 65867
9 8 412169
10 9 183571
3 9 646463
6 8 911293
6 9 178083
6 3 470761
8 4 493752
4 6 785212
4 3 821348

output:

6218303

result:

ok 1 number(s): "6218303"

Test #33:

score: 0
Accepted
time: 530ms
memory: 72580kb

input:

250
109 16 1
132 109 1
132 16 1
127 16 0
127 109 0
127 132 0
133 16 1
133 127 1
133 109 0
124 16 1
127 124 0
124 132 1
41 109 1
41 127 1
132 41 0
44 16 0
44 133 1
127 44 1
121 16 0
121 133 0
121 109 1
127 48 0
48 133 1
48 109 0
16 204 1
204 124 1
204 127 0
16 236 1
124 236 0
132 236 1
17 127 1
124 1...

output:

87

result:

ok 1 number(s): "87"

Test #34:

score: 0
Accepted
time: 518ms
memory: 72556kb

input:

250
21 37 0
1 37 0
21 1 0
147 21 1
37 147 1
1 147 0
118 21 1
147 118 1
37 118 0
21 105 1
147 105 1
105 1 1
155 37 0
155 147 0
155 1 1
202 21 0
202 118 1
202 147 0
21 109 0
118 109 1
109 37 1
146 147 0
118 146 0
146 37 0
21 128 1
128 105 1
147 128 0
206 21 1
206 105 0
206 1 1
129 147 1
105 129 1
129 ...

output:

87

result:

ok 1 number(s): "87"

Test #35:

score: 0
Accepted
time: 527ms
memory: 73256kb

input:

250
25 109 1
25 14 0
109 14 1
109 195 1
25 195 0
195 14 1
119 109 0
119 195 1
25 119 1
231 109 1
231 195 1
231 14 0
32 25 1
32 195 1
14 32 0
156 109 1
119 156 0
156 195 1
195 196 0
196 119 0
25 196 0
109 53 0
231 53 0
14 53 1
223 109 0
223 231 0
195 223 0
189 109 0
119 189 1
25 189 0
195 215 0
32 21...

output:

92

result:

ok 1 number(s): "92"

Test #36:

score: 0
Accepted
time: 530ms
memory: 72608kb

input:

250
130 100 0
108 130 1
108 100 0
96 100 0
96 130 1
96 108 0
100 155 1
155 96 1
108 155 1
100 218 0
155 218 1
218 96 0
100 159 0
159 96 1
159 130 0
130 40 0
96 40 1
40 108 1
136 100 0
218 136 0
96 136 0
100 137 1
137 136 1
218 137 1
208 100 1
208 137 0
208 218 1
155 177 0
218 177 0
177 96 0
235 218 ...

output:

150

result:

ok 1 number(s): "150"

Test #37:

score: 0
Accepted
time: 530ms
memory: 72732kb

input:

250
127 223 1
109 223 0
109 127 0
245 127 0
223 245 1
109 245 0
223 19 1
245 19 1
19 109 1
245 97 1
97 19 1
109 97 1
206 19 0
97 206 1
206 109 0
97 195 1
195 206 0
195 109 0
225 206 0
225 195 1
225 109 1
61 195 0
61 225 1
109 61 0
174 97 0
195 174 0
174 109 1
231 97 1
174 231 0
109 231 1
174 102 0
1...

output:

160

result:

ok 1 number(s): "160"

Test #38:

score: 0
Accepted
time: 527ms
memory: 72780kb

input:

250
20 75 1
103 20 1
75 103 0
196 75 1
20 196 1
196 103 0
20 223 1
196 223 1
223 103 0
196 55 0
55 223 0
103 55 1
223 158 0
158 55 0
158 103 0
198 55 1
198 158 1
103 198 0
93 158 0
198 93 1
93 103 0
66 198 1
66 93 1
103 66 1
93 9 1
66 9 1
103 9 1
23 66 0
9 23 0
103 23 0
56 9 1
56 23 0
103 56 1
23 53...

output:

192

result:

ok 1 number(s): "192"

Test #39:

score: 0
Accepted
time: 541ms
memory: 73244kb

input:

250
13 48 1
48 118 1
13 118 0
13 207 0
207 48 0
118 207 0
48 163 1
163 207 0
163 118 0
207 90 0
90 163 0
90 118 0
163 1 1
90 1 0
1 118 1
154 90 1
154 1 0
118 154 1
1 77 0
77 154 1
77 118 1
59 154 0
77 59 0
59 118 1
77 116 0
116 59 0
118 116 1
174 59 1
174 116 0
118 174 0
116 107 0
107 174 0
107 118 ...

output:

186

result:

ok 1 number(s): "186"

Test #40:

score: 0
Accepted
time: 525ms
memory: 72752kb

input:

250
72 47 317
47 181 260
72 181 242
72 84 332
84 47 320
84 181 866
188 72 974
188 84 677
47 188 686
72 133 916
84 133 103
181 133 965
221 47 947
221 84 312
181 221 530
72 67 547
188 67 747
67 84 397
72 171 571
171 188 984
47 171 397
23 84 72
23 188 459
47 23 266
72 228 693
228 133 329
84 228 963
19 ...

output:

69340

result:

ok 1 number(s): "69340"

Test #41:

score: 0
Accepted
time: 522ms
memory: 72460kb

input:

250
81 38 92
81 44 465
44 38 715
29 38 736
81 29 822
44 29 595
250 38 377
29 250 231
81 250 443
109 38 265
29 109 243
109 44 193
71 81 459
71 29 976
44 71 742
38 92 789
250 92 272
29 92 430
91 38 594
250 91 262
81 91 136
95 29 151
95 250 552
81 95 937
38 60 733
60 109 769
29 60 903
38 204 612
204 10...

output:

68209

result:

ok 1 number(s): "68209"

Test #42:

score: 0
Accepted
time: 532ms
memory: 73140kb

input:

250
156 184 875
229 184 42
229 156 543
238 156 570
238 184 946
238 229 612
1 156 343
238 1 903
184 1 556
184 49 705
49 238 814
49 229 160
156 217 74
217 238 775
217 229 439
156 33 837
33 1 566
33 238 577
35 156 625
1 35 0
184 35 729
238 11 69
11 1 298
11 184 216
201 184 95
201 49 433
238 201 525
241...

output:

77098

result:

ok 1 number(s): "77098"

Test #43:

score: 0
Accepted
time: 533ms
memory: 72704kb

input:

250
141 53 965
141 131 292
53 131 103
53 201 713
141 201 874
131 201 776
168 141 302
201 168 575
131 168 548
135 141 937
135 168 455
135 201 91
53 102 620
102 201 730
102 131 761
141 240 178
135 240 103
240 168 510
53 98 836
201 98 126
141 98 48
90 141 490
135 90 665
201 90 753
152 168 322
152 135 4...

output:

123435

result:

ok 1 number(s): "123435"

Test #44:

score: 0
Accepted
time: 527ms
memory: 72584kb

input:

250
244 93 170
32 244 680
93 32 457
34 93 414
244 34 127
32 34 902
244 125 437
125 34 347
32 125 975
137 34 326
137 125 446
137 32 903
139 125 643
137 139 918
139 32 294
137 55 168
139 55 458
55 32 707
110 139 402
110 55 902
110 32 836
84 137 589
55 84 275
84 32 764
28 55 420
84 28 663
28 32 37
124 ...

output:

147574

result:

ok 1 number(s): "147574"

Test #45:

score: 0
Accepted
time: 531ms
memory: 73124kb

input:

250
117 237 81
94 237 646
94 117 541
131 117 543
237 131 370
94 131 603
237 207 721
207 131 604
94 207 571
131 199 567
207 199 716
94 199 84
111 207 912
111 199 693
111 94 533
75 199 57
111 75 463
94 75 9
111 105 963
105 75 228
105 94 921
20 75 50
20 105 667
20 94 106
105 59 991
59 20 117
94 59 444
...

output:

158634

result:

ok 1 number(s): "158634"

Test #46:

score: 0
Accepted
time: 522ms
memory: 72928kb

input:

250
53 25 918
166 25 823
166 53 448
223 53 139
223 25 249
223 166 254
25 137 324
223 137 41
166 137 194
223 243 845
137 243 196
166 243 236
137 95 399
95 243 21
166 95 320
74 243 816
95 74 939
74 166 357
165 95 559
74 165 338
165 166 802
139 74 980
139 165 955
139 166 427
165 130 330
139 130 686
130...

output:

162976

result:

ok 1 number(s): "162976"

Test #47:

score: 0
Accepted
time: 532ms
memory: 73428kb

input:

250
167 59 3727
98 167 415377
98 59 367821
1 59 434763
167 1 759915
98 1 870438
127 59 521996
1 127 493689
167 127 805229
62 59 16384
1 62 83435
98 62 188092
167 146 222427
1 146 312488
146 98 671034
187 59 647673
187 127 798161
187 1 865936
59 46 147329
46 127 12140
167 46 547685
250 1 196742
127 2...

output:

68546516

result:

ok 1 number(s): "68546516"

Test #48:

score: 0
Accepted
time: 522ms
memory: 72672kb

input:

250
239 45 849626
35 239 18734
35 45 598913
122 45 524698
122 239 856901
35 122 580163
62 45 872015
62 122 194181
239 62 55074
45 229 455623
122 229 657467
229 35 761521
239 240 210328
122 240 597281
35 240 947297
23 45 749468
23 62 357993
23 122 859171
45 201 297289
62 201 422066
239 201 287210
16 ...

output:

69651831

result:

ok 1 number(s): "69651831"

Test #49:

score: 0
Accepted
time: 525ms
memory: 73044kb

input:

250
110 61 844342
61 11 239200
11 110 869967
190 110 770263
190 61 199804
190 11 176143
110 226 734643
226 190 849517
61 226 107970
110 218 59158
190 218 559122
11 218 651062
110 22 677008
22 226 796711
22 190 146902
210 61 969946
190 210 483902
210 11 599125
236 110 565411
226 236 814674
236 61 664...

output:

75589000

result:

ok 1 number(s): "75589000"

Test #50:

score: 0
Accepted
time: 533ms
memory: 72632kb

input:

250
176 152 156004
112 152 962004
176 112 214244
176 32 996641
152 32 616291
32 112 463361
195 176 712932
195 32 926096
195 112 851687
176 224 785426
195 224 890244
224 112 647116
152 52 701373
52 32 430404
112 52 543614
176 53 378901
53 224 932391
195 53 196420
176 218 970360
218 53 677517
224 218 ...

output:

126682427

result:

ok 1 number(s): "126682427"

Test #51:

score: 0
Accepted
time: 525ms
memory: 72560kb

input:

250
155 140 319733
140 97 351891
97 155 969156
155 130 680170
140 130 646528
130 97 740973
140 7 291681
7 130 687236
97 7 942380
20 130 731597
20 7 566763
20 97 468517
246 7 603355
246 20 188682
97 246 651296
234 7 650893
234 246 323315
97 234 475241
149 246 707282
149 234 817673
97 149 992185
234 4...

output:

149669431

result:

ok 1 number(s): "149669431"

Test #52:

score: 0
Accepted
time: 521ms
memory: 73192kb

input:

250
24 127 773254
127 151 206763
151 24 849913
24 144 732831
127 144 976946
144 151 531411
225 127 791443
225 144 168042
225 151 832138
144 88 483606
225 88 714791
151 88 962425
225 156 505980
156 88 718178
151 156 438750
88 94 439918
156 94 607010
94 151 445222
156 57 845937
94 57 543318
57 151 858...

output:

161833608

result:

ok 1 number(s): "161833608"

Test #53:

score: 0
Accepted
time: 523ms
memory: 73088kb

input:

250
197 24 964354
197 210 566406
24 210 655820
24 178 680581
197 178 916959
210 178 859370
156 197 440740
178 156 468234
156 210 582291
214 178 44368
156 214 140759
214 210 425996
157 156 517394
157 214 433385
210 157 161802
214 175 375122
157 175 10179
210 175 451302
157 112 695978
112 175 133392
1...

output:

158169479

result:

ok 1 number(s): "158169479"

Test #54:

score: 0
Accepted
time: 25ms
memory: 72780kb

input:

13
4 1 92
4 13 73
1 13 11
9 1 91
4 9 67
13 9 57
11 4 89
9 11 45
11 13 78
1 8 82
8 9 46
4 8 96
10 1 33
10 9 68
10 13 59
12 4 54
12 11 17
13 12 95
2 1 8
8 2 85
4 2 70
9 6 16
6 11 71
6 13 53
9 5 37
6 5 98
5 11 65
7 4 51
11 7 88
9 7 80
3 1 88
3 2 3
3 4 92

output:

960

result:

ok 1 number(s): "960"

Test #55:

score: 0
Accepted
time: 16ms
memory: 72528kb

input:

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

output:

36

result:

ok 1 number(s): "36"

Test #56:

score: 0
Accepted
time: 11ms
memory: 72528kb

input:

6
6 2 342868
6 3 164103
2 3 629720
1 6 977298
1 2 339017
1 3 978681
4 2 320998
4 3 192509
4 1 740435
5 2 445180
5 1 706218
5 4 186285

output:

3217164

result:

ok 1 number(s): "3217164"

Test #57:

score: 0
Accepted
time: 8ms
memory: 72408kb

input:

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

output:

46

result:

ok 1 number(s): "46"