QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607656 | #6619. Line Graph Matching | wsxcb# | TL | 44ms | 29172kb | C++17 | 1.1kb | 2024-10-03 15:42:22 | 2024-10-03 15:42:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second
const int N = 2e5 + 5;
vector<int>e[N];
array<int, 3>edge[N];
vector<int>E[N];
ll val[N];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
edge[i] = {u, v, w};
e[u].pb(i);
e[v].pb(i);
}
for (int i = 1; i <= m; i++) {
auto [u, v, w] = edge[i];
for (auto t : e[u]) {
if (t != i)
E[i].pb(t);
}
for (auto t : e[v]) {
if (t != i)
E[i].pb(t);
}
}
for (int i = 1; i <= m; i++) {
val[i] += edge[i][2];
if (E[i].size() == 1) {
val[E[i][0]] += edge[i][2];
}
}
ll s = 0;
for (int i = 1; i <= m; i++)
s += edge[i][2];
if (m % 2) {
ll mi = 2e9 + 7;
for (int i = 1; i <= m; i++)
mi = min(mi, val[i]);
//cout << mi << ' ' << s << '\n';
s -= mi;
}
cout << s << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 16860kb
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: 0ms
memory: 16120kb
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: 14660kb
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: 0ms
memory: 15720kb
input:
3 2 1 2 1 2 3 2
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 2ms
memory: 15408kb
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: 4ms
memory: 16256kb
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: 0
Accepted
time: 41ms
memory: 23400kb
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:
49946352904479
result:
ok 1 number(s): "49946352904479"
Test #8:
score: 0
Accepted
time: 40ms
memory: 23016kb
input:
100000 99999 18547 67114 422842568 19693 8496 779855087 51167 18426 915314526 44355 50210 119625069 12950 4056 197918233 61098 35840 389797594 73234 63511 535160500 47702 90861 938540623 91579 13299 509661983 40747 91690 12909789 58827 9678 282003419 35422 9560 815634437 20241 26517 840659336 93110 ...
output:
49888240257242
result:
ok 1 number(s): "49888240257242"
Test #9:
score: 0
Accepted
time: 41ms
memory: 23944kb
input:
100000 99999 25520 2623 154792857 1765 4073 799245045 99749 45838 839182660 98677 58205 524737144 76603 55928 568414838 33898 29608 922164506 88693 78722 1129358 10136 25336 739395975 69484 68712 25516570 4182 48506 515454795 76879 82061 553583242 22090 97332 926700970 89926 81197 558183206 29662 27...
output:
49857536488340
result:
ok 1 number(s): "49857536488340"
Test #10:
score: 0
Accepted
time: 43ms
memory: 22444kb
input:
100000 99999 72042 25409 725983606 49873 52758 607305688 63918 42603 224757632 7040 60725 735261849 3210 8822 867145685 41268 9352 80358220 74405 56201 74682882 42091 83435 349445732 31907 73608 324631368 21709 60815 811088936 66131 97870 754621619 50607 17635 563355884 70943 80969 555360875 34584 9...
output:
49910465246498
result:
ok 1 number(s): "49910465246498"
Test #11:
score: 0
Accepted
time: 44ms
memory: 29172kb
input:
100000 99999 10715 1068 751750885 90390 22200 868370908 4434 24771 510418099 43553 9661 532496008 33027 9192 426178660 52737 21946 668997040 54761 24810 41781655 58813 57402 176782581 36930 1300 814097421 18356 21290 10495515 24941 88423 65937531 63377 57167 347397631 72045 91846 74407074 79044 6065...
output:
50022292101614
result:
ok 1 number(s): "50022292101614"
Test #12:
score: -100
Time Limit Exceeded
input:
100000 99999 5344 45257 932283560 5344 41988 113638743 5344 82319 686963255 5344 83414 26663701 5344 1956 977496010 5344 95966 782365014 5344 46605 39879251 5344 96628 313951622 5344 8440 511271264 5344 49973 635326375 5344 65604 192267424 5344 47220 582095220 5344 66302 248860581 5344 73608 9553914...