QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721803 | #6619. Line Graph Matching | xzin | WA | 74ms | 15600kb | C++14 | 840b | 2024-11-07 16:54:05 | 2024-11-07 16:54:07 |
Judging History
answer
#include <bits/stdc++.h>
#define N 101000
using namespace std;
int n, m, mn, sum, sz[N];
vector<int> vec[N];
vector<int> val[N];
int dfs(int p, int f) {
int mnp = 1e9;
for(int i = 0;i < vec[p].size(); i++) {
int v = vec[p][i], w = val[p][i];
if(v == f) continue;
mnp = min(mnp, dfs(v, p)); sz[p] += sz[v] + 1;
if(sz[v] % 2 == 0) mnp = min(mnp, w);
}
return mnp;
}
int main() {
cin>>n>>m;
sum = 0; mn = 1e9;
for(int i = 1;i <= m; i++) {
int u, v, w;
cin>>u>>v>>w;
mn = min(mn, w); sum += w;
val[u].push_back(w);
val[v].push_back(w);
vec[u].push_back(v);
vec[v].push_back(u);
}
if(m % 2) {
if(m == n - 1) mn = dfs(1, 0);
sum -= mn;
}
cout<<sum<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8296kb
input:
5 6 1 2 1 1 3 2 1 4 3 4 3 4 4 5 5 2 5 6
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 2ms
memory: 8428kb
input:
6 5 1 2 4 2 3 1 3 4 3 4 5 2 5 6 5
output:
12
result:
ok 1 number(s): "12"
Test #3:
score: 0
Accepted
time: 0ms
memory: 8468kb
input:
5 5 1 2 1 2 3 2 3 4 3 4 5 4 5 1 5
output:
14
result:
ok 1 number(s): "14"
Test #4:
score: 0
Accepted
time: 2ms
memory: 8276kb
input:
3 2 1 2 1 2 3 2
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 1ms
memory: 8272kb
input:
3 3 1 2 3 2 3 1 3 1 2
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 8336kb
input:
6 7 1 2 1 2 3 2 3 4 3 4 1 4 4 5 5 5 6 6 6 4 7
output:
27
result:
ok 1 number(s): "27"
Test #7:
score: -100
Wrong Answer
time: 74ms
memory: 15600kb
input:
100000 99999 54273 5761 179909546 6472 21601 924153552 610 22693 767540137 37784 2454 951330587 24457 93770 781030280 36098 27 448166069 21292 43394 244510129 58047 86330 869927899 18770 83124 20504174 24036 92856 8370757 92492 21932 734860719 43776 77624 226721931 15746 70738 429430538 71204 87185 ...
output:
178219295
result:
wrong answer 1st numbers differ - expected: '49946352904479', found: '178219295'