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;
const int N=1010, M=5010;
int n, m, cnt, deg[N], dep[N];
vector<int> g[N];
pair<pair<int, int>, int> edge[M];
void dfs(int u, int p){
dep[u]=dep[p]+1;
for (int v:g[u]) if (v!=p) dfs(v, u);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
int ans=0;
for (int i=1; i<=m; ++i){
int u, v, w; cin >> u >> v >> w;
if (w) edge[++cnt]={{u, v}, w}, ans+=w;
else g[u].push_back(v), g[v].push_back(u), ++deg[u], ++deg[v];
}
int u=find(deg+1, deg+n+1, 1)-deg;
dfs(u, 0);
int mx=0;
for (int i=1; i<=cnt; ++i) if ((dep[edge[i].first.first]&1)==(dep[edge[i].first.second]&1)) mx=max(mx, edge[i].second);
cout << ans-mx << '\n';
return 0;
}
# | 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... |