提交时间:2021-05-17 17:57:25

运行 ID: 19605

#include<bits/stdc++.h> using namespace std; int n; char Head[51]; char Tail[51]; int Flag[51]={1}; int Answer,Count=1; int Solitaire(int x){ for(int i=2;i<=n;i++){ if(Head[i]==Tail[x]&&Flag[i]!=1&&i!=x){ Flag[i]=1; Count++; Solitaire(i); } } if(Count>Answer){ Answer=Count; Count--; Flag[x]=0; return 0; } } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>Head[i]; cin>>Tail[i]; } Solitaire(1); cout<<Answer; return 0; }