QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#502413#2645. Collapsemakrav5 5795ms13336kbC++204.3kb2024-08-03 05:08:382024-08-03 05:08:39

Judging History

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

  • [2024-08-03 05:08:39]
  • 评测
  • 测评结果:5
  • 用时:5795ms
  • 内存:13336kb
  • [2024-08-03 05:08:38]
  • 提交

answer

#include "collapse.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

const int K = 1000;

struct dsu {
	int n, cmp;
	vector<int> par, siz;
	dsu() = default;
	dsu(int n_) {
		cmp = 0;
		n = n_;
		par.assign(n, 0);
		iota(all(par), 0);
		siz.assign(n, 1);
	}

	int get(int v) {
		return (par[v] == v ? v : par[v] = get(par[v]));
	}

	void merge(int u, int v) {
		u = get(u);
		v = get(v);
		if (u == v) return;
		cmp--;
		if (siz[v] > siz[u]) swap(u, v);
		par[v] = u;
		siz[u] += siz[v];
	}
};		

std::vector<int> simulateCollapse(
	int N,
	std::vector<int> T,
	std::vector<int> X,
	std::vector<int> Y,
	std::vector<int> W,
	std::vector<int> P
) {
	int n = N;
	int c = sz(X);
	vector<vector<pair<int, int>>> qrs(c);
	for (int i = 0; i < sz(W); i++) {
		qrs[W[i]].pb({P[i], i});
	}
	vector<int> ans(sz(W));
	vector<vector<int>> gr(n);
	vector<int> used1(n), used_dfs(n);
	int step = 0;
	for(int i = 0; i < c; i++){
		if(X[i]>Y[i])swap(X[i],Y[i]);
	}
	for (int i = 0; i < c; i += K) {
		unordered_set<ll> ch_edg;
		unordered_set<ll> LOL;
		for (int j = i; j < min(c, i + K); j++) {
			if (T[j] == 1 && ch_edg.find(X[j] * 1ll * N + Y[j]) == ch_edg.end()) {
				LOL.insert(X[j] * 1ll * n + Y[j]);
			}
			ch_edg.insert(X[j] * 1ll * N + Y[j]);
		}
		vector<vector<int>> by_rig(n), by_left(n);
		unordered_set<ll> usedE;
		for (int j = i - 1; j >= 0; j--) {
			if (T[j] == 0 && usedE.find(X[j]*1ll*n+Y[j])==usedE.end()&&ch_edg.find(X[j] * 1ll * n + Y[j]) == ch_edg.end()) {
				by_rig[max(X[j], Y[j])].pb(min(X[j], Y[j]));
				by_left[min(X[j], Y[j])].pb(max(X[j], Y[j]));
			}
			usedE.insert(X[j]*1ll*n+Y[j]);
		}
		vector<vector<pair<int, int>>> qnums(n - 1);
		for (int j = i; j < min(c, i + K); j++) {
			for (auto &[el, num] : qrs[j]) {
				qnums[el].pb({j, num});
			}
		}
		dsu d(n);
		for (int I = 0; I < n - 1; I++) {
			d.cmp++;
			for (auto &u : by_rig[I]) d.merge(u, I);
			for (auto &[time, numb] : qnums[I]) {
				step++;
				unordered_set<ll> add_edges = LOL;
				for (int j = i; j <= time; j++) {
					if (T[j] == 0) {
						add_edges.insert(X[j] * 1ll * n + Y[j]);
					} else {
						add_edges.erase(X[j] * 1ll * n + Y[j]);
					}
				}
				unordered_set<int> rdfs;
				for (auto E : add_edges) {
					ll u = E / n, v = E % n;
					if (max(u, v) <= I) {
						u = d.get(u);
						v = d.get(v);
						if (u != v) {
							if (used1[u] != step) gr[u].clear();
							if (used1[v] != step) gr[v].clear();
							used1[u] = step;
							used1[v] = step;
							gr[u].pb(v);
							gr[v].pb(u);
							rdfs.insert(u);
							rdfs.insert(v);
						}
					}
				}
				int ccmp = d.cmp;
				auto dfs = [&](int v, auto&&dfs) -> void {
					used_dfs[v] = step;
					for (auto &u : gr[v]) {
						if (used_dfs[u] != step) {
							ccmp--;
							dfs(u, dfs);
						}
					}
				};
				for (auto &u : rdfs) {
					if (used_dfs[u] != step) {
						dfs(u, dfs);
					}
				}
				ans[numb] += ccmp;
			}
		}
		iota(all(d.par), 0);
		d.siz.assign(n, 1);
		d.cmp = 0;
		for (int I = n - 1; I >= 1; I--) {
			d.cmp++;
			for (auto &u : by_left[I]) d.merge(u, I);
			for (auto &[time, numb] : qnums[I - 1]) {
				step++;
				unordered_set<ll> add_edges = LOL;
				for (int j = i; j <= time; j++) {
					if (T[j] == 0) {
						add_edges.insert(X[j] * 1ll * n + Y[j]);
					} else {
						add_edges.erase(X[j] * 1ll * n + Y[j]);
					}
				}
				unordered_set<int> rdfs;
				for (auto E : add_edges) {
					int u = E / n, v = E % n;
					if (min(u, v) >= I) {
						u = d.get(u);
						v = d.get(v);
						if (u != v) {
							if (used1[u] != step) gr[u].clear();
							if (used1[v] != step) gr[v].clear();
							used1[u] = step;
							used1[v] = step;
							gr[u].pb(v);
							gr[v].pb(u);
							rdfs.insert(u);
							rdfs.insert(v);
						}
					}
				}
				int ccmp = d.cmp;
				auto dfs = [&](int v, auto&&dfs) -> void {
					used_dfs[v] = step;
					for (auto &u : gr[v]) {
						if (used_dfs[u] != step) {
							ccmp--;
							dfs(u, dfs);
						}
					}
				};
				for (auto &u : rdfs) {
					if (used_dfs[u] != step) {
						dfs(u, dfs);
					}
				}
				ans[numb] += ccmp;
			}
		}
	}
	return ans;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 61ms
memory: 4584kb

input:

2 5000 5000
0 0 1
1 0 1
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 0 1
0 0 1
1 1 0
...

output:

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

result:

ok 5000 lines

Test #5:

score: 5
Accepted
time: 82ms
memory: 4252kb

input:

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

output:

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

result:

ok 5000 lines

Test #6:

score: 5
Accepted
time: 293ms
memory: 4568kb

input:

100 4950 5000
0 38 3
0 56 61
0 87 71
0 64 10
0 92 60
0 44 11
0 3 7
0 81 41
0 43 72
0 73 61
0 77 23
0 63 20
0 64 16
0 11 37
0 51 97
0 80 10
0 56 2
0 76 42
0 69 74
0 26 28
0 40 37
0 5 35
0 25 22
0 95 35
0 89 34
0 3 88
0 26 17
0 40 8
0 8 79
0 48 6
0 18 94
0 76 75
0 44 22
0 30 94
0 50 41
0 92 45
0 11 20...

output:

2
2
2
2
2
2
2
2
2
3
2
2
5
2
2
7
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
4
2
2
3
2
2
2
68
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
7
3
2
2
2
2
2
2
2
2
2
13
2
2
2
9
9
71
3
2
7
2
2
2
13
2
9
3
2
2
2
2
2
3
2
2
8
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
7
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 5000 lines

Test #7:

score: 5
Accepted
time: 3ms
memory: 4632kb

input:

5000 1 5000
0 4285 4296
0 174
0 1012
0 3399
0 3238
0 1816
0 4133
0 3019
0 4260
0 2930
0 4630
0 1081
0 2725
0 4468
0 3870
0 1078
0 2021
0 2532
0 4271
0 3007
0 4647
0 3279
0 1541
0 4631
0 2309
0 2625
0 1049
0 3253
0 1274
0 4488
0 4202
0 885
0 2684
0 2656
0 1036
0 2263
0 2196
0 4410
0 1974
0 2852
0 113...

output:

4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
...

result:

ok 5000 lines

Test #8:

score: 5
Accepted
time: 5ms
memory: 4604kb

input:

5000 13 5000
0 1437 2917
0 4619 3686
0 4797 4454
0 3445 4933
0 561 1988
1 4797 4454
1 1988 561
0 1409 339
0 2874 2680
0 1266 4421
0 803 4698
0 3886 2422
1 3686 4619
1 2249
7 4184
3 4331
3 1568
4 4846
1 3533
12 2754
6 232
4 3193
9 2272
7 2268
10 4048
8 4216
6 3985
0 4840
12 3065
5 2887
12 592
2 1092
...

output:

4999
4998
4998
4997
4996
4998
4998
4997
4995
4996
4997
4997
4997
4999
4999
4996
4997
4994
4997
4996
4999
4997
4996
4995
4995
4997
4998
4996
4998
4996
4999
4998
4995
4996
4997
4996
4998
4996
4994
4996
4996
4998
4997
4996
4999
4998
4993
4997
4997
4998
4997
4999
4996
4992
4998
5000
4993
4998
4997
4997
...

result:

ok 5000 lines

Test #9:

score: 5
Accepted
time: 86ms
memory: 4996kb

input:

5000 5000 5000
0 975 2469
1 2469 975
0 3116 3798
0 2112 4747
0 1861 3986
1 3798 3116
0 2915 1795
0 1550 3770
0 433 3583
1 4747 2112
0 1153 4006
0 2233 3268
1 4006 1153
0 4456 1149
0 4 655
0 4058 2897
1 2915 1795
0 1725 1423
0 2206 1507
1 4058 2897
1 1423 1725
1 4 655
1 433 3583
0 4821 1327
0 1407 24...

output:

4961
4981
4994
4986
4974
4993
4987
4987
4981
4998
4986
4994
4997
4974
4986
4998
5000
4988
4993
4982
4993
4984
4993
4965
4996
4968
4997
4963
4986
4996
4996
4982
4996
4993
4998
4992
4972
4999
4999
4991
4996
5000
4999
4987
4961
4991
4993
4979
4994
4981
4999
4983
4989
4975
4996
4993
4989
4998
5000
4991
...

result:

ok 5000 lines

Test #10:

score: 5
Accepted
time: 305ms
memory: 5104kb

input:

5000 5000 5000
0 3449 1421
1 1421 3449
0 253 3884
1 253 3884
0 2908 3268
0 4948 3871
0 2908 3908
1 2908 3268
0 4186 1306
1 3871 4948
1 2908 3908
1 4186 1306
0 3741 2117
0 1391 4186
0 778 509
0 1597 2117
1 4186 1391
0 2908 4020
1 4020 2908
1 1597 2117
0 4948 3179
0 196 4186
0 2117 1579
1 778 509
1 41...

output:

4464
4508
4509
4635
4763
4516
4646
4766
4525
4772
4789
4388
4910
4779
4907
4409
4907
4724
4669
4873
4850
4545
4383
4438
4509
4850
4537
4859
4725
4828
4532
4826
4629
4299
4957
4477
4992
4543
4805
4656
4996
4832
4465
4729
4923
4717
4364
4564
4456
4388
4680
4534
4800
4457
4734
4747
4793
4740
4926
4532
...

result:

ok 5000 lines

Test #11:

score: 5
Accepted
time: 528ms
memory: 5376kb

input:

5000 5000 5000
0 1900 2340
0 4130 1922
0 4969 1233
0 2827 3942
0 3982 1431
0 3486 3980
0 3997 2929
0 2449 3118
0 3060 2285
0 971 2628
0 1938 1814
0 240 4209
0 2249 2974
0 2372 1784
0 3729 4064
0 3636 2763
0 3518 2722
0 3948 2501
0 200 1592
0 3783 1348
0 3343 1642
0 4576 3200
0 1460 1735
0 3938 2178
...

output:

4740
2997
3403
4239
2531
4424
2465
2519
3310
2420
3799
1923
3777
2055
3063
3748
2640
4713
4792
3263
3068
3434
4461
2712
3717
1634
1751
2536
4249
4870
4382
3349
3591
4942
3143
2777
4796
4931
1675
3006
3737
3628
1197
2662
2059
3752
3720
3887
4469
4127
4526
1813
4369
4559
4582
3506
4054
3771
3815
2561
...

result:

ok 5000 lines

Test #12:

score: 5
Accepted
time: 453ms
memory: 5380kb

input:

5000 5000 5000
0 976 1107
0 2771 4969
0 976 3008
0 155 976
0 3048 3929
0 4548 2155
0 3811 3048
0 4982 3048
0 4308 976
0 3048 2390
0 3048 3912
0 3250 2339
0 2660 976
0 976 2307
0 3048 4635
0 3048 1329
0 952 1913
0 4996 8
0 3717 976
0 2022 4914
0 3048 457
0 976 740
0 976 991
0 2989 3048
0 976 4925
0 3...

output:

3578
2489
4843
4622
3701
3077
4881
2925
2394
2513
3902
2867
4299
4769
4021
2773
3530
3958
4462
4306
4707
2657
4068
4490
2105
3627
3887
2680
4428
4258
3269
4525
4126
2759
3107
4294
2508
2012
3755
3588
4804
3768
3122
2763
3570
1818
3020
4546
3826
3357
2310
3197
3512
3293
3145
3089
4023
3132
4052
2462
...

result:

ok 5000 lines

Subtask #2:

score: 0
Time Limit Exceeded

Test #13:

score: 30
Accepted
time: 25ms
memory: 7392kb

input:

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

result:

ok 100000 lines

Test #15:

score: 30
Accepted
time: 1667ms
memory: 12856kb

input:

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

output:

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

result:

ok 100000 lines

Test #16:

score: 30
Accepted
time: 194ms
memory: 7612kb

input:

10 45 100000
0 9 7
0 0 6
0 3 2
0 7 8
0 3 7
0 1 0
0 2 8
0 8 3
0 0 4
0 8 4
0 7 0
0 6 1
0 0 3
0 8 1
0 5 8
0 5 1
0 7 6
0 4 2
0 9 3
0 0 9
0 3 1
0 3 6
0 5 3
0 9 8
0 2 9
0 7 1
0 4 6
0 0 8
0 9 5
0 6 2
0 4 5
0 4 7
0 0 2
0 6 9
0 5 6
0 5 0
0 8 6
0 1 9
0 1 2
0 1 4
0 4 3
0 9 4
0 5 7
0 2 7
0 5 2
1 6
14 6
26 6
6 6...

output:

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

result:

ok 100000 lines

Test #17:

score: 30
Accepted
time: 2831ms
memory: 13336kb

input:

100 100000 100000
0 12 26
1 12 26
0 44 29
1 44 29
0 21 32
1 21 32
0 81 30
1 30 81
0 93 39
0 26 5
1 39 93
0 93 87
0 60 13
1 87 93
1 13 60
1 26 5
0 26 84
1 26 84
0 26 50
0 44 32
1 26 50
0 61 86
1 61 86
1 32 44
0 69 59
0 68 92
0 37 21
0 5 53
1 37 21
0 87 78
0 64 9
1 64 9
1 53 5
1 92 68
0 31 66
1 66 31
...

output:

19
25
62
11
13
61
20
31
79
83
63
50
94
9
35
31
17
17
86
56
98
9
69
38
54
91
78
11
69
30
8
41
10
33
5
45
48
70
76
80
9
59
7
58
24
15
35
97
96
46
88
38
19
38
86
18
49
70
61
14
37
58
5
91
35
23
30
29
61
56
13
55
12
63
56
74
67
40
92
12
81
14
42
29
68
93
10
10
19
84
60
32
77
67
44
96
38
98
9
13
21
97
60...

result:

ok 100000 lines

Test #18:

score: 30
Accepted
time: 5023ms
memory: 7660kb

input:

100 4950 100000
0 84 47
0 31 87
0 62 83
0 54 79
0 41 94
0 87 43
0 46 70
0 84 93
0 33 91
0 0 87
0 36 88
0 8 74
0 86 39
0 99 23
0 74 33
0 86 11
0 29 8
0 24 23
0 5 97
0 7 68
0 9 8
0 17 22
0 75 55
0 61 35
0 32 18
0 20 38
0 99 89
0 89 80
0 96 29
0 5 27
0 90 6
0 36 1
0 83 49
0 69 33
0 70 36
0 4 94
0 51 74...

output:

8
2
2
2
2
2
2
2
2
2
2
2
2
9
2
2
2
2
2
2
2
2
2
6
2
2
2
2
2
2
2
2
2
2
2
2
2
2
9
2
2
2
2
12
2
2
2
19
65
2
2
2
2
2
2
58
9
2
2
2
2
7
2
11
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
8
89
2
2
2
2
2
2
2
2
9
2
2
2
2
2
2
2
2
2
2
2
2
2
2
87
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
21
2
2
2
2
65
2
2
2
2
2
2
2
2
2
2...

result:

ok 100000 lines

Test #19:

score: 0
Time Limit Exceeded

input:

1000 100000 100000
0 401 876
0 420 792
0 965 268
0 909 871
0 736 337
0 341 634
0 112 317
0 685 606
0 778 506
0 162 289
0 375 590
0 874 77
0 434 986
0 78 804
0 743 760
0 290 466
0 721 828
0 44 145
0 601 101
0 223 651
0 327 860
0 105 727
0 447 93
0 680 298
0 868 502
0 130 527
0 567 523
0 871 862
0 423...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #28:

score: 30
Accepted
time: 25ms
memory: 7312kb

input:

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

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 100000 lines

Test #29:

score: 30
Accepted
time: 41ms
memory: 6912kb

input:

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

output:

3
2
2
4
5
2
2
4
3
2
3
5
4
2
4
3
3
2
4
2
5
2
2
4
2
5
2
4
4
4
2
4
2
2
3
4
2
4
3
5
4
3
4
4
4
5
3
5
5
3
2
3
4
5
2
3
4
3
4
3
5
2
5
4
5
2
4
2
5
2
4
5
4
3
2
3
3
3
2
4
5
4
5
4
4
2
3
4
3
3
2
3
2
3
3
2
4
4
4
5
3
3
4
5
4
4
5
3
3
2
5
3
5
4
3
2
5
4
4
5
3
3
4
4
3
5
4
2
4
2
2
4
2
3
4
2
5
5
4
4
2
2
3
3
4
2
2
5
5
4
...

result:

ok 100000 lines

Test #30:

score: 30
Accepted
time: 95ms
memory: 7480kb

input:

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

result:

ok 100000 lines

Test #32:

score: 30
Accepted
time: 3035ms
memory: 7344kb

input:

100 500 100000
0 75 20
0 23 42
0 53 70
0 11 28
0 23 67
0 74 63
0 93 4
0 13 43
0 96 72
0 2 65
0 43 96
0 86 52
0 77 38
0 89 33
0 85 84
0 55 48
0 8 20
0 7 18
0 43 62
0 38 44
0 42 24
0 98 6
0 92 66
0 17 33
0 4 70
0 12 74
0 13 99
0 79 63
0 53 14
0 38 22
0 54 41
0 61 44
0 85 21
0 25 38
0 38 28
0 81 87
0 7...

output:

8
19
7
7
5
51
5
8
16
8
3
6
5
3
42
3
6
5
9
15
3
9
7
6
5
26
12
4
22
22
3
13
11
6
99
3
79
2
30
3
2
9
56
5
67
2
43
4
12
3
28
26
11
6
5
18
2
6
72
6
17
2
11
18
48
86
3
3
85
6
10
3
7
36
5
3
6
12
5
3
38
3
3
11
9
93
54
60
8
22
35
4
34
16
48
6
11
5
5
31
99
43
60
5
11
8
2
21
69
3
94
50
8
3
8
3
8
6
25
28
3
6
2
...

result:

ok 100000 lines

Test #33:

score: 30
Accepted
time: 5795ms
memory: 7340kb

input:

100 4950 100000
0 50 40
0 87 50
0 72 73
0 74 65
0 2 4
0 29 28
0 20 28
0 15 99
0 13 56
0 31 5
0 5 89
0 28 10
0 84 6
0 19 92
0 38 96
0 89 86
0 21 10
0 18 35
0 84 28
0 86 80
0 69 45
0 33 62
0 3 45
0 81 22
0 0 43
0 12 41
0 81 58
0 34 4
0 53 65
0 55 43
0 71 18
0 60 17
0 44 18
0 12 6
0 55 94
0 87 41
0 42 ...

output:

2
4
2
2
2
2
4
2
2
3
2
2
2
2
2
2
5
2
2
2
2
2
2
2
2
2
2
4
2
2
5
2
2
2
14
2
16
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
41
2
2
2
2
2
14
2
2
2
2
2
2
2
2
6
2
2
2
2
2
2
2
2
8
2
2
2
2
2
2
2
2
2
28
2
2
2
2
2
14
2
2
12
2
2
2
2
2
2
2
2
2
3
2
2
2
2
10
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
6
78
2
2
2
2
2
2
2
2
2
2
1...

result:

ok 100000 lines

Test #34:

score: 0
Time Limit Exceeded

input:

1000 75000 100000
0 312 514
0 320 439
0 100 448
0 646 280
0 535 701
0 199 217
0 178 777
0 843 287
0 996 52
0 587 444
0 728 395
0 882 610
0 875 656
0 971 990
0 656 990
0 549 684
0 766 968
0 969 956
0 15 757
0 978 467
0 736 621
0 673 44
0 911 944
0 555 47
0 385 922
0 897 648
0 352 936
0 157 311
0 645 ...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%