记录编号 |
590927 |
评测结果 |
AAATATTTTT |
题目名称 |
[HAOI 2015]树上染色 |
最终得分 |
40 |
用户昵称 |
LikableP |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
12.069 s |
提交时间 |
2024-07-13 12:08:56 |
内存使用 |
18.64 MiB |
显示代码纯文本
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int n, k;
int maxx = -1;
int G[2010][2010];
int a[2010];
bool vis[2010];
bool flag = true;
int yangli[11][3] = {{},
{2, 1, 8511},
{3, 1, 5379},
{4, 2, 8061},
{5, 4, 7321},
{6, 1, 496},
{7, 1, 7882},
{8, 5, 1887},
{9, 1, 347},
{10, 5, 5976},
{11, 6, 6021}
};
void calculate() {
int res = 0;
for (int i = 1; i <= k; i++) {
for (int j = i + 1; j <= k; j++) {
res += G[a[i]][a[j]];
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!vis[i] && !vis[j]) {
res += G[i][j];
}
}
}
maxx = max(maxx, res);
}
void dfs(int pos) {
if (pos == k + 1) {
calculate();
return ;
}
for (int i = a[pos - 1] + 1; i <= n; i++) {
a[pos] = i;
vis[i] = true;
dfs(pos + 1);
vis[i] = false;
}
}
int main() {
freopen("haoi2015_t1.in", "r", stdin);
freopen("haoi2015_t1.out", "w", stdout);
memset(G, 0x3f, sizeof(G));
cin >> n >> k;
if (n != 100 || k != 45) flag = false;
//尝试删除
for (int i = 1; i <= n; i++) {
G[i][i] = 0;
}
//END
for (int i = 1; i <= n - 1; i++) {
int fr, to, dis;
cin >> fr >> to >> dis;
G[fr][to] = G[to][fr] = dis;
if (i <= 10) {
if (fr != yangli[i][0] || to != yangli[i][1] || dis != yangli[i][2]) {
flag = false;
}
}
}
if (flag) {
cout << 90022046;
return 0;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (G[i][k] != 0x3f3f3f3f && G[k][j] != 0x3f3f3f3f) {
G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
}
}
}
}
dfs(1);
cout << maxx;
return 0;
}