#include <bits/stdc++.h>
using namespace std;
struct Road{
int s, e, c;
Road(){};
Road(int x, int y, int z){
s = x, e = y, c = z;
}
bool operator < (const Road &A) const{
return s<A.s;
}
} R[5010];
vector<int> G[1010];
int N,M,A,B,C,cnt,I[1010],X[1010],D[1010],xn,S,E,sum;
void DFS(int u, int p) {
X[u] = xn++;
for(int v : G[x]){
if(v == p) continue;
DFS(v, u);
}
}
int main() {
cin >> N >> M;
for(int i = 0; i < M; i++){
cin >> A >> B >> C;
if(C) R[cnt++] = Road(A,B,C);
else{
G[A].push_back(B);
G[B].push_back(A);
I[A]++;
I[B]++;
}
sum += C;
}
for(int i = 1; i <= N; i++){
if(I[i] == 1){
DFS(i,i);
break;
}
}
for(int i = 0; i < cnt; i++){
R[i].s = X[R[i].s];
R[i].e = X[R[i].e];
if(R[i].s > R[i].e) swap(R[i].s, R[i].e);
}
sort(R, R + cnt);
for(int i=0; i<cnt; i++){
S = R[i].s;
E = R[i].e;
if((E - S) & 1) continue;
for(int j = E; j < N; j++) D[j] = max(D[j], D[S] + R[i].c);
}
cout << sum - D[N-1] << '\n';
}
Compilation message
training.cpp: In function 'void DFS(int, int)':
training.cpp:20:19: error: 'x' was not declared in this scope
20 | for(int v : G[x]){
| ^