#include <bits/stdc++.h>
using namespace std;
const int N = 205, B = 2005, I = 1e9;
int s, t, n, m, as[N], sum;
struct flow
{
int h[N], tot = 1, d[N], cur[N], a[N];
queue<int> q;
struct edge
{
int to, val, nxt;
}e[B << 1];
void add(int u, int v, int w)
{
e[++tot] = {v, w, h[u]}; h[u] = tot;
e[++tot] = {u, 0, h[v]}; h[v] = tot;
}
bool bfs()
{
while(q.size()) q.pop();
for(int i = 1; i <= n; i++) cur[i] = h[i], d[i] = 0;
q.push(s); d[s] = 1;
while(q.size())
{
int u = q.front(); q.pop();
for(int i = h[u]; i; i = e[i].nxt)
{
int v = e[i].to;
if(e[i].val && !d[v])
{
d[v] = d[u] + 1;
if(v == t) return 1;
q.push(v);
}
}
}
return 0;
}
int dfs(int u, int sum)
{
if(u == t) return sum;
int res = sum;
for(int &i = cur[u]; i; i = e[i].nxt)
{
int v = e[i].to, w = e[i].val;
if(w == 0 || d[v] != d[u] + 1) continue;
int k = dfs(v, min(res, w));
if(k == 0) d[v] = 0;
else
{
e[i].val -= k, e[i ^ 1].val += k; res -= k;
if(res == 0) break;
}
}
return sum - res;
}
void undo()
{
for(int i = 2; i <= tot; i += 2)
{
e[i].val += e[i ^ 1].val;
e[i ^ 1].val = 0;
}
}
int dinic()
{
int sum = 0; undo();
while(bfs()) sum += dfs(s, I);
return sum;
}
int ta[N], fa[N], ct;
vector<int> g[N];
struct node
{
int u, v, w;
friend bool operator < (node a, node b) {return a.w > b.w;}
}ed[N];
int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
void merge(int x, int y)
{
x = find(x), y = find(y);
if(x == y) return;
fa[x] = y; g[y].insert(begin(g[y]), begin(g[x]), end(g[x]));
}
void solve(int l, int r)
{
if(l == r) return;
s = a[l], t = a[r]; ed[++ct] = {s, t, dinic()};
int na = 0, mid = l - 1;
for(int i = l; i <= r; i++)
{
if(d[a[i]]) a[++mid] = a[i];
else ta[++na] = a[i];
}
for(int i = 1; i <= na; i++) a[i + mid] = ta[i];
solve(l, mid); solve(mid + 1, r);
}
void solve()
{
for(int i = 1; i <= n; i++) a[i] = i, fa[i] = i, g[i].push_back(i);
solve(1, n); sort(ed + 1, ed + ct + 1);
for(int i = 1; i <= ct; i++)
{
sum += ed[i].w;
merge(ed[i].u, ed[i].v);
}
int u = find(1);
for(int i = 1; i <= n; i++) as[i] = g[u][i - 1];
}
}f;
int u, v, w;
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++)
{
scanf("%d%d%d", &u, &v, &w);
f.add(u, v, w), f.add(v, u, w);
}
f.solve();
printf("%d\n", sum);
for(int i = 1; i <= n; i++) printf("%d ", as[i]);
printf("\n");
return 0;
}
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |
461. Hamming Distance | 1748. Sum of Unique Elements |
897. Increasing Order Search Tree | 905. Sort Array By Parity |
1351. Count Negative Numbers in a Sorted Matrix | 617. Merge Two Binary Trees |
1450. Number of Students Doing Homework at a Given Time | 700. Search in a Binary Search Tree |
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |