• 카테고리

    질문 & 답변
  • 세부 분야

    알고리즘 · 자료구조

  • 해결 여부

    미해결

테케는 통과하는데 왜 틀렸을까요

23.09.26 17:47 작성 조회수 145

0

#include<iostream>

#include<vector>

using namespace std;

int n,d,p,root,visited[54];

vector<int>adj[54];

int dfs(int here){

visited[here]=1;

int ret=0;

if(adj[here].size()==0)return 1;

for(int there:adj[here]){

if(visited[there])continue;

ret+=dfs(there);

}

return ret;

}

int main(){

cin >> n;

for(int i=0;i<n;i++){

cin >> p;

if(p==-1){

root=i;

continue;

}

adj[p].push_back(i);

}

cin >> d;

if(d==root)cout<<0<<"\n";

else{

visited[d]=1;

cout << dfs(root) << "\n";

}

}

답변 2

·

답변을 작성해보세요.

0

조현성님의 프로필

조현성

질문자

2023.09.27

죄송합니다 그래서 재 질문하려고 다시 올렸는데 들여쓰기가 안되네요 해결책을 찾아보고 올리겠습니다 ㅠㅠ

저거 링크로 남겨주시면 됩니다. ㅎㅎ 방법은 0주차 : 질문하는 법에 제가 설명드리고 있어용

0

안녕하세요 현성님 ㅎㅎ

들여쓰기가 되어있지 않는 코드는 디버깅이 힘듭니다.. ㅎㅎ

0주차 : 질문하는 법 보시고 다시 질문 부탁드립니다.

 

감사합니다.