NBUT 1218 You are my brother
Posted Fighting Heart
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NBUT 1218 You are my brother相关的知识,希望对你有一定的参考价值。
$dfs$。
记录一下每一个节点的深度就可以了。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> using namespace std; int n; int dep[3000],in[3000]; vector<int>g[3000]; void dfs(int x,int y) { dep[x]=y; for(int i=0;i<g[x].size();i++) dfs(g[x][i],y+1); } int main() { while(~scanf("%d",&n)) { for(int i=0;i<=2000;i++) g[i].clear(); memset(in,0,sizeof in); for(int i=1;i<=n;i++) { int A,B; scanf("%d%d",&A,&B); g[B].push_back(A); in[A]++; } for(int i=1;i<=2000;i++) { if(in[i]==0) { dfs(i,1); } } if(dep[1]==dep[2]) printf("You are my brother\n"); else if(dep[1]>dep[2]) printf("You are my elder\n"); else printf("You are my younger\n"); } return 0; }
以上是关于NBUT 1218 You are my brother的主要内容,如果未能解决你的问题,请参考以下文章
You are not late! You are not early!
You are pushing more GUIClips than you are popping. Make sure they are balanced(Unity Console错误提示)