#include "dreaming.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<ull> vull;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpi> vvpi;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
vi visited,visited2;
vvpi paths;
ll maxdist = 0;
int node = 0;
int found = 0;
void dfs(int pos,int prev,ll dist,int can){
if(visited[pos])return;
visited[pos] = 1;
if(can)visited2[pos] = 1;
if(dist > maxdist)node = pos;
maxdist = max(maxdist,dist);
for(auto edge:paths[pos]){
if(edge.F == prev)continue;
dfs(edge.F,pos,dist+edge.S);
}
}
void dfs2(int pos,int prev,ll dist){
if(found)return;
if(visited[pos])return;
visited[pos] = 1;
if(dist < 0){
node = pos;
found = 1;
}
for(auto edge:paths[pos]){
if(edge.F == prev)continue;
dfs(edge.F,pos,dist-edge.S);
}
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
if(n==1)return 0;
paths = vvpi(n);
visited2 = vi(n,0);
vl distances(n,0);
FOR(i,0,m){
paths[A[i]].pb({B[i],T[i]});
paths[B[i]].pb({A[i],T[i]});
}
for(int i=0;i<n;i++){
if(visited2[i])continue;
visited = vi(n,0);
maxdist = 0;
node = i;
dfs(i,-1,0,0);
visited = vi(n,0);
int head = node;
node = i;
maxdist = 0;
dfs(head,-1,0,1);
head = node;
visited = vi(n,0);
found = 0;
dfs2(head,-1,maxdist/2);
visited = vi(n,0);
head = node;
maxdist = 0;
dfs(head,-1,0,0);
distances[i] = maxdist;
}
sort(distances.rbegin(),distances.rend());
if(m == n-1)return distances[0];
return distances[0] + distances[1] + L;
}
Compilation message
dreaming.cpp: In function 'void dfs(int, int, ll, int)':
dreaming.cpp:59:35: error: too few arguments to function 'void dfs(int, int, ll, int)'
59 | dfs(edge.F,pos,dist+edge.S);
| ^
dreaming.cpp:49:6: note: declared here
49 | void dfs(int pos,int prev,ll dist,int can){
| ^~~
dreaming.cpp: In function 'void dfs2(int, int, ll)':
dreaming.cpp:75:35: error: too few arguments to function 'void dfs(int, int, ll, int)'
75 | dfs(edge.F,pos,dist-edge.S);
| ^
dreaming.cpp:49:6: note: declared here
49 | void dfs(int pos,int prev,ll dist,int can){
| ^~~