# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54566 |
2018-07-04T06:16:52 Z |
김세빈(#1491) |
Training (IOI07_training) |
C++11 |
|
8 ms |
724 KB |
#include <bits/stdc++.h>
using namespace std;
vector <int> V[1010], T[1010];
int P[1010], D[1010], K[1010];
int A[5050], B[5050], C[5050];
int n, m, k, sum;
void dfs(int p, int r)
{
for(auto t: T[p]){
if(t != r){
P[t] = p;
D[t] = D[p] + 1;
dfs(t, p);
}
}
}
int lca(int a, int b)
{
if(D[a] < D[b]) swap(a, b);
for(;D[a] != D[b];) a = P[a];
for(;a != b;) a = P[a], b = P[b];
return a;
}
void dp(int p, int r)
{
int a, b, x, y, s;
int rt = 0;
for(auto t: T[p]){
if(t != r){
dp(t, p);
rt += K[t];
}
}
for(auto t: V[p]){
a = A[t], b = B[t], s = C[t];
x = y = 0;
if(a != p){
a = P[a];
for(;a!=p;){
for(auto q: T[a]){
if(q != x && q != P[a]) s += K[q];
}
x = a, a = P[a];
}
}
if(b != p){
b = P[b];
for(;b!=p;){
for(auto q: T[b]){
if(q != y && q != P[b]) s += K[q];
}
y = b, b = P[b];
}
}
for(auto q: T[p]) if(q != x && q != y) s += K[q];
rt = max(rt, s);
}
K[p] = rt;
// printf("%d %d\n", p, K[p]);
}
int main()
{
int i, a, b, c;
scanf("%d%d", &n, &m);
for(i=0;i<m;i++){
scanf("%d%d%d", &a, &b, &c);
if(c == 0) T[a].push_back(b), T[b].push_back(a);
else A[k] = a, B[k] = b, C[k++] = c;
sum += c;
}
dfs(1, 0);
for(i=0;i<k;i++){
if(~(D[A[i]] + D[B[i]]) & 1){
V[lca(A[i], B[i])].push_back(i);
}
}
dp(1, 0);
printf("%d\n", sum - K[1]);
return 0;
}
Compilation message
training.cpp: In function 'int main()':
training.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
training.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a, &b, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
412 KB |
Output is correct |
2 |
Correct |
2 ms |
540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
608 KB |
Output is correct |
2 |
Correct |
8 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |