#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 x, int r)
{
X[x] = xn++;
for(int a : G[x]){
if(a==r) continue;
DFS(a,x);
}
}
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)%2) continue;
for(int j=E; j<N; j++) D[j] = max(D[j],D[S]+R[i].c);
}
cout << sum - D[N-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |