Submission #95246

#TimeUsernameProblemLanguageResultExecution timeMemory
95246easruiTraining (IOI07_training)C++14
10 / 100
7 ms504 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...