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 = 2e5 + 2;
struct st{
int a, b;
long long c;
} ar[N], b[N];
int n, m, pf[N];
long long ans;
bool cmp(st a, st b){
if(a.a == b.a)
return a.b < b.b;
return a.a < b.a;
}
int main(){
cin >> n >> m;
for(int i = 1; i <= m; i ++){
cin >> ar[i].a >> ar[i].b >> ar[i].c;
if(ar[i].a > ar[i].b)
swap(ar[i].a, ar[i].b);
}
sort(ar + 1, ar + m + 1, cmp);
int sz = 0;
for(int i = 1; i <= m; i ++){
int pt = i;
while(pt + 1 <= m && ar[pt + 1].a == ar[i].a && ar[pt + 1].b == ar[i].b)
ar[i].c += ar[++ pt].c;
b[++ sz] = ar[i];
i = pt;
}
m = sz;
for(int i = 1; i <= m; i ++)
ar[i] = b[i];
for(int i = 1; i <= m; i ++){
ans += ar[i].c / 2;
ar[i].c %= 2;
pf[ ar[i].a ] += ar[i].c;
pf[ ar[i].b ] -= ar[i].c;
}
int mx = 0;
for(int i = 1; i <= n; i ++){
pf[i] += pf[i - 1];
mx = max(mx, pf[i]);
}
cout << ans + (mx + 1) / 2 << endl;
}
# | 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... |