#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair<int,int> > adj[100010];
int dfs(int v, int par)
{
int mx = 0, secondmx = 0;
if(adj[v].size() == 1)
return 0;
for(int i = 0; i < adj[v].size(); i++)
{
int u = adj[v][i].first;
if(u != par)
{
int val = dfs(u,v);
int len = adj[v][i].second;
if(val + len >= mx)
{
secondmx = mx;
mx = val + len;
}
}
}
return secondmx;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < M ; i++)
{
int v = R[i][0],u = R[i][1],l = L[i];
adj[v].push_back(make_pair(u,l));
adj[u].push_back(make_pair(v,l));
}
for(int i = 0; i < K; i++)
if(P[i] == 0)
return 0;
return dfs(0,0);
}
Compilation message
crocodile.cpp: In function 'int dfs(int, int)':
crocodile.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[v].size(); i++)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
121744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Memory limit exceeded |
36 ms |
262144 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Memory limit exceeded |
599 ms |
262144 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |