이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pf push_front
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
const int MAX = 2001;
vi g[MAX];
bool is[MAX];
ll ans = 0;
void dfs(int from , int p, ll dis){
if(g[from].size()==1){
ans = max(ans,dis);
return;
}
for(int to : g[from]){
if(to==p)continue;
dfs(to,from,dis+1);
}
}
/*
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for(int i = 0; i< M; i++){
int a = R[i][0];
int b = R[i][1];
g[a].pb(b);
g[b].pb(a);
}
dfs(0,-1,0);
return ans;
}
*/
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for(int i = 0; i< M; i++){
int a = R[i][0];
int b = R[i][1];
g[a].pb(b);
g[b].pb(a);
}
for(int i =0 ;i < K; i++){
if(P[i]==0) return 0;
}
dfs(0,-1,0);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |