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 "longesttrip.h"
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define ins insert
#define fr first
#define sc second
#define vll vector<ll>
#define sz size()
using namespace std;
const ll N = 260;
const ll inf = 1e9 + 7;
vector<vll> g(N);
ll d[N],p[N];
void dfs(ll v){
for(auto i : g[v]){
if(d[i] != inf)continue;
p[i] = v;
d[i] = d[v] + 1;
dfs(i);
}
}
void cl(){
for(ll i=0;i<N;i++){
d[i] = inf;
p[i] = i;
}
}
pair<ll,ll> find(){
ll mx = -1, x = 0;
for(ll i=0;i<N;i++){
if(d[i] != inf && d[i] > mx){
mx = d[i];
x = i;
}
}
return {mx, x};
}
vector<int> longest_trip(int n, int D){
ll i,j;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(are_connected({i},{j})){
g[i].pb(j);
g[j].pb(i);
}
}
}
ll rt = 0, ans = 0;
for(i=0;i<n;i++){
cl();
d[i] = 0;
dfs(i);
auto [mx, x] = find();
if(mx < ans){
mx = ans;
rt = i;
}
}
cl();
d[rt] = 0;
dfs(rt);
auto [mx, x] = find();
vll v;
while(x != p[x]){
v.pb(x);
x = p[x];
}
v.pb(x);
return v;
}
# | 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... |