QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329470#7769. Axium Crisiszhaohaikun75 2338ms176004kbC++144.2kb2024-02-16 19:23:312024-02-16 19:23:31

Judging History

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

  • [2024-02-16 19:23:31]
  • 评测
  • 测评结果:75
  • 用时:2338ms
  • 内存:176004kb
  • [2024-02-16 19:23:31]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
const int N = 20;
int _, o, n, height[2 * N * (1 << 18)], f[N][1 << 17], val[N];
vector <pair <int, int>> v[N], path;
vector <int> edge[N][N];
vector <array <int, 4>> g[N][1 << 17];
vector <pair <string, pair <int, pair <int, int>>>> tt;
void dfs(int rt, int x, int fa, int num, string st) {
	if (num) tt.emplace_back(st, make_pair(num, make_pair(rt, x)));
	for (auto i: v[x])
		if (i.first != fa) {
			if (val[i.second] != 1) dfs(rt, i.first, x, num | (1 << (i.second - 1)), st + "0");
			if (val[i.second] != 0) dfs(rt, i.first, x, num | (1 << (i.second - 1)), st + "1");
		}
}
void dfs2(int rt, int x, int fa) {
	for (auto i: v[x])
		if (i.first != fa) {
			edge[rt][i.first] = edge[rt][x];
			edge[rt][i.first].push_back(i.second);
			dfs2(rt, i.first, x);
		}
}
void cmax(int id, int a, int b, int c, int d, int v) {
	if (f[c][d] + v > f[a][b]) {
		f[a][b] = f[c][d] + v;
		g[a][b].emplace_back(array <int, 4> {id, c, d, v});
	}
}
void work(int pos, int x, int y) {
	while (g[x][y].size() && g[x][y].back()[0] > pos) g[x][y].pop_back();
	if (g[x][y].empty()) return;
	// cout << "# " << x << " " << y << " " << g[x][y].back()[0] << " " << g[x][y].back()[1] << " " << g[x][y].back()[2] << " " << g[x][y].back()[3] << endl;
	if (g[x][y].back()[3]) {
		// puts("!");
		path.emplace_back(tt[g[x][y].back()[0]].second.second.first, tt[g[x][y].back()[0]].second.second.second);
		int z = 0;
		for (int i: edge[tt[g[x][y].back()[0]].second.second.first][tt[g[x][y].back()[0]].second.second.second]) val[i] = tt[g[x][y].back()[0]].first[z++] - '0';
	} work(g[x][y].back()[0] - 1, g[x][y].back()[1], g[x][y].back()[2]);
}
void work() {
	path.clear();
	read(n);
	ms(f, 0);
	F(i, 1, n) v[i].clear();
	F(i, 1, n)
		F(j, 1, n)
			edge[i][j].clear();
	tt.clear();
	F(i, 1, n - 1) {
		int x, y; read(x), read(y), read(val[i]);
		x++, y++;
		v[x].emplace_back(y, i);
		v[y].emplace_back(x, i);
	}
	F(i, 1, n) dfs(i, i, 0, 0, ""), dfs2(i, i, 0);
	sort(all(tt));
	// cout << n << " " << tt.size() << " " << N * N * 2 << endl;
	// F(i, 0, SZ(tt)) cout << tt[i].first << " " << tt[i].second << endl;
	F(i, 0, SZ(tt) - 1) {
		int k = 0;
		while (k < tt[i + 1].first.size() && k < tt[i].first.size() && tt[i + 1].first[k] == tt[i].first[k]) k++;
		height[i] = k;
		// cout << "! " << i << " " << height[i] << endl;
	} height[SZ(tt)] = 0;
	int full = (1 << (n - 1)) - 1;
	F(i, 0, n)
		F(j, 0, full)
			g[i][j].clear();
	F(i, 0, SZ(tt)) {
		DF(j, height[i], 0) {
			int k = full ^ tt[i].second.first;
			for (int t = k; ; t = (t - 1) & k) {
				cmax(i, height[i], t | tt[i].second.first, j, t, (int) tt[i].first.size() - j);
				if (t == 0) break;
			}
		}
		int lst = i - 1;
		while ((~lst) && height[lst] > height[i]) {
			int k = tt[lst].second.first;
			for (int j = k; ; j = (j + 1) | k) {
				cmax(i, height[i], j, height[lst], j, 0);
				if (!(j & tt[i].second.first)) cmax(i, height[i], j | tt[i].second.first, height[lst], j, (int) tt[i].first.size() - height[lst]);
				// f[height[lst]][j] = 1e9;
				if (j == full) break;
			}
			lst--;
		}
	}
	int ans = 0, ii = -1, jj = -1;
	F(i, 0, n)
		F(j, 0, full)
			if (f[i][j] > ans) {
				ans = f[i][j];
				ii = i, jj = j;
			}
	cout << ans + 1 << '\n';
	work(SZ(tt), ii, jj);
	cout << path.size() << '\n';
	F(i, 1, n - 1) cout << min(1, val[i]) << " "; cout << '\n';
	for (auto i: path) cout << i.first - 1 << " " << i.second - 1 << '\n';
}
signed main() {
	// freopen("axiumcrisis.in", "r", stdin);
	// freopen("axiumcrisis.out", "w", stdout);
	cout << "1\n";
	read(_), read(o);
	while (_--) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 362ms
memory: 76072kb

input:

1000 0
4
0 2 0
2 3 0
2 1 0
4
3 2 1
0 2 1
1 2 2
4
0 2 2
0 1 0
3 0 0
4
1 2 1
3 2 0
2 0 1
4
0 2 0
0 3 0
2 1 0
4
0 2 1
0 3 1
0 1 1
4
3 1 0
2 1 2
3 0 2
4
3 1 1
3 0 1
2 3 0
4
1 0 0
2 0 2
2 3 2
4
1 2 0
3 0 0
2 3 2
3
2 1 0
0 2 1
4
3 0 1
1 2 1
2 3 0
4
2 1 0
3 0 1
1 0 1
4
3 2 1
3 1 1
0 1 1
4
1 2 1
1 3 0
3 0 1...

output:

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

result:

ok Accepted. Good Job!

Test #2:

score: 10
Accepted
time: 368ms
memory: 75760kb

input:

1000 0
4
2 0 0
2 1 0
0 3 0
4
2 1 0
2 0 0
1 3 0
4
1 3 0
1 0 0
2 1 0
4
0 1 2
2 1 2
1 3 2
4
0 2 2
3 2 0
1 3 1
4
1 3 0
2 3 0
3 0 0
4
1 2 1
3 0 0
0 2 0
4
3 2 1
2 1 1
0 1 0
4
2 1 0
3 2 0
2 0 0
4
1 3 0
2 3 0
3 0 2
4
2 0 0
3 0 1
1 2 1
4
0 2 2
3 1 2
2 1 2
4
1 3 2
3 0 2
2 0 2
4
2 0 0
2 1 2
2 3 1
4
0 1 2
2 3 1...

output:

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

result:

ok Accepted. Good Job!

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 1094ms
memory: 77316kb

input:

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

result:

ok Accepted. Good Job!

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 10
Accepted
time: 1126ms
memory: 77912kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Test #6:

score: 10
Accepted
time: 1116ms
memory: 75836kb

input:

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

result:

ok Accepted. Good Job!

Test #8:

score: 10
Accepted
time: 1172ms
memory: 81644kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Subtask #5:

score: 10
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 10
Accepted
time: 1301ms
memory: 81088kb

input:

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

result:

ok Accepted. Good Job!

Subtask #6:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 10
Accepted
time: 1672ms
memory: 125648kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Test #12:

score: 10
Accepted
time: 1660ms
memory: 125064kb

input:

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

result:

ok Accepted. Good Job!

Subtask #8:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

input:

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

output:

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

result:


Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 2338ms
memory: 176004kb

input:

3000 3
8
1 2 0
4 6 1
2 4 1
3 4 1
4 0 0
5 6 0
4 7 1
8
6 0 0
2 6 1
5 4 1
0 4 1
2 3 0
7 1 1
5 1 0
17
8 7 0
15 7 0
5 7 1
4 5 1
2 5 1
16 5 1
10 16 0
14 5 1
6 2 0
3 5 1
12 7 0
14 0 0
3 1 0
9 5 1
13 5 1
16 11 0
14
4 3 0
2 10 1
12 1 0
9 7 0
6 13 0
5 11 0
8 12 1
6 3 1
4 1 1
0 10 0
2 8 0
7 5 1
0 11 1
8
7 6 0
...

output:

1
7
2
0 1 1 1 0 0 1 
3 1
5 0
8
1
0 1 1 1 0 1 0 
3 7
10
4
0 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 
4 8
5 10
0 6
12 15
14
1
0 1 0 0 0 0 1 1 1 0 0 1 1 
13 9
7
2
0 0 1 0 0 1 0 
1 4
2 7
7
2
1 1 1 1 1 1 0 
0 7
6 3
8
2
1 1 1 0 1 1 0 
5 2
3 0
7
3
1 1 1 0 0 1 1 
0 5
2 1
7 6
8
4
1 0 1 0 0 1 0 0 0 1 
2 6
3 9
10 0
4 7
...

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 2322ms
memory: 172964kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Subtask #10:

score: 0
Skipped

Dependency #5:

100%
Accepted

Dependency #8:

0%