#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
#define des first
#define val second
lli act,res;
lli visitados[100002],MIN[2];
vector<pair<lli,lli> > hijos[100002],caminos[100002];
lli DSF(lli pos, lli padre) {
lli tiem,a,k = 0;
visitados[pos] = 1;
for (auto h : hijos[pos]) {
if (h.des == padre) {tiem = h.val;continue;}
a = DSF(h.des,pos);
caminos[pos].push_back({h.des,a});
if (a > k) k = a;
}
return a + tiem;
}
void optimo(lli pos, lli padre, lli suma) {
lli dd,prim = 0;
lli a,seg = 0;
for (auto h : caminos[pos]) {
if (h.val > prim){
seg = prim;
prim = h.val;
dd = h.des;
}
else if (h.val > seg) seg = h.val;
}
a = max(prim,suma);
if (a < MIN[act]) MIN[act] = a;
if (a > res) res = a;
for (auto h : hijos[pos]) {
if (h.des == padre) continue;
if (h.des == dd) optimo(h.des,pos,max(suma,seg)+h.val);
else optimo(h.des,pos,max(suma,prim)+h.val);
}
}
void procesa(lli pos) {
lli a = DSF(pos,0);
optimo(pos,0,0);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
rep(i,0,M-1) {
hijos[A[i]].push_back({B[i],T[i]});
hijos[B[i]].push_back({A[i],T[i]});
}
act = 0;
res = 0;
MIN[0] = MIN[1] = 1ll<<62;
rep(i,1,N) {
if (act == 2) break;
if (visitados[i] == 0) {
procesa(i);
act++;
}
}
act = MIN[0] + MIN[1] + L;
res = max(res,act);
return res;
}
Compilation message
dreaming.cpp: In function 'void procesa(long long int)':
dreaming.cpp:58:9: warning: unused variable 'a' [-Wunused-variable]
58 | lli a = DSF(pos,0);
| ^
dreaming.cpp: In function 'void optimo(long long int, long long int, long long int)':
dreaming.cpp:51:9: warning: 'dd' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | if (h.des == dd) optimo(h.des,pos,max(suma,seg)+h.val);
| ^~
dreaming.cpp: In function 'long long int DSF(long long int, long long int)':
dreaming.cpp:28:16: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | return a + tiem;
| ^~~~
dreaming.cpp:28:16: warning: 'tiem' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
22464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
22464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
7632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
22464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |