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;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
int N, M, D[1001];
vector<int> adj[1001];
vector<array<int, 3>> G;
void dfs(int v, int p) {
D[v] = D[p] + 1;
for(auto u : adj[v]) {
if(u == p) continue;
dfs(u, v);
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
for(int l = 0; l < M; l++) {
int U, V, C; cin >> U >> V >> C;
if(C == 0)
adj[U].push_back(V),
adj[V].push_back(U);
if(C >= 1) G.push_back({U, V, C});
}
int res = 0, src = 0;
for(int l = 1; l <= N; l++) {
if(adj[l].size() == 1) src = l;
}
D[src] = -1; dfs(src, src);
for(auto e : G) {
int U = e[0], V = e[1], C = e[2];
if(abs(D[V] - D[U]) & 1)
res += C;
}
cout << res << "\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... |