我知道这么写暴力法肯定会有问题,但还是尝试了下,果然最后两个测试点不通过
# include <iostream>
using namespace std;
int AddrNow[100010];
char Info[100010];
int AddrNxt[100010];
int N;
int main()
{
int start1, start2;
cin >> start1 >> start2 >> N;
for(int i=0;i<N;++i)
cin >> AddrNow[i] >> Info[i] >> AddrNxt[i];
int i, j, cnt = 0;
for(i=0;i<N;++i){
cnt = 0;
for(j=0;j<N;++j)
if(AddrNxt[j] == AddrNow[i])
cnt++;
if(cnt == 2)
break;
}
if(cnt == 2)
cout << AddrNow[i];
else
cout << -1;
return 0;
}