#include<cstdio> #include<vector> using namespace std; const int maxn = 100; vector<int>G[maxn]; int p[maxn]; void dfs(int x,int root) { for(int i = 0;i < G[x].size();i++) { int v = G[x][i]; if(v != root) { p[v] = x; dfs(v,x); } } } int main() { freopen("input.txt","r",stdin); int edge; scanf("%d",&edge); for(int i = 0;i < edge;i++) { int x1,x2; scanf("%d%d",&x1,&x2); G[x1].push_back(x2); G[x2].push_back(x1); } int root; scanf("%d",&root); dfs(root,-1); return 0; }
这道题目的独特之处在于只保存边