Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;const int N = 100021;typedef long long ll;int mod = 1000000007;int pre[N];int fa[N], son[N];int main(){//freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);int n;while (~scanf("%d", &n)){int x, y, ans = -1;memset(pre, 0, sizeof(pre));for (int i = 0; i < n; i++){scanf("%d%d", &x, &y);fa[i] = x;son[i] = y;if (pre[y] != 0){ans = i;}elsepre[y] = x;}x = y = -1;if (ans != -1){