#include using namespace std; #define ff first #define ss second #define pb push_back #define ll long long #define ull unsigned long long #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define mst(ss,b) memset(ss,b,sizeof(ss)); #ifdef Cyberdebut #define dbg(x) cerr << #x << " = " << x << endl #else #define dbg(x) #endif typedef pair pii; ll gcd(ll a, ll b){return a ? gcd(b%a,a):b;} ll pow_mod(ll x, ll n, ll mod){ll ret=1LL;while(n){if(n&1)ret=ret*x%mod;x=x*x%mod;n>>=1;}return ret;} const int inf = 0x3f3f3f3f; const ll INF = (1LL<<62)-1; const ll mod = 1e9+7; const int N = 3e3+5; const int maxn = 10005; const int maxm = 200005; struct Edge{ int from, to, next; bool cut;//是否为桥的标记 }edge[maxm]; int head[maxn], tol; int low[maxn], dfn[maxn], stk[maxn]; int idx, top; bool instk[maxn]; bool cut[maxn]; int add_block[maxn];//删除一个点后增加的连通块 int bridge; void init(){ tol = 0; memset(head, -1, sizeof(head)); memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); memset(instk, 0, sizeof(instk)); memset(cut, 0, sizeof(cut)); memset(add_block, 0, sizeof(add_block)); idx = top = bridge = 0; } void addedge(int u, int v){ edge[tol].from = u; edge[tol].to = v; edge[tol].next = head[u]; edge[tol].cut = 0; head[u] = tol++; } void Tarjan(int u, int fa){ int v; low[u] = dfn[u] = ++idx; stk[top++] = u; instk[u] = 1; int son = 0; for(int i=head[u]; i!=-1; i=edge[i].next){ v = edge[i].to; if(v == fa)continue; if(!dfn[v]){ son++; Tarjan(v, u); low[u] = min(low[u], low[v]); //桥 //一条无向边(u,v)是桥,当且仅当(u,v)为树枝边,且满足DFS(u) dfn[u]){ bridge++; edge[i].cut = 1; edge[i^1].cut = 1; } //割点 //一个顶点u是割点,当且仅当满足(1)或(2) (1) u为树根,且u有多于一个子树。 //(2) u不为树根,且满足存在(u,v)为树枝边(或称父子边, //即u为v在搜索树中的父亲),使得DFS(u)<=Low(v) if(u != fa && low[v] >= dfn[u]){//不是树根 cut[u] = 1; add_block[u]++; } } else if(low[u] > dfn[v])low[u] = dfn[v]; } //树根,分支数大于1 if(u == fa && son > 1)cut[u] = 1; if(u == fa)add_block[u] = son-1; instk[u] = 0; top--; } int n, m; int g[N][N]; int main(){ while(~scanf("%d%d", &n, &m)){ init(); mst(g, 0); for(int i=1; i<=m; i++){ int u, v, w; scanf("%d%d%d", &u, &v, &w); g[u][v] += w; g[v][u] += w; } for(int i=1; i<=n; i++)for(int j=i+1; j<=n; j++)if(g[i][j])addedge(i, j), addedge(j, i); int ans = inf; if(bridge){ for(int i=0; i