This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |