FZU

题目链接

题目大意

  略

解题思路

  套路题。

代码

const int maxn = 1e6+10;
const int maxm = 1e6+10;
struct Node {
	int m, f;
} node[maxn];
char ans[maxn];
bool dfs(int now, int x, int l) {
	if (now==x) {
        ans[l] = 0;
        return 1;
    }
	if (!now) return 0;
	if (node[now].f) {
		ans[l] = 'F';
        if (dfs(node[now].f, x, l+1)) return 1;
	}
	if (node[now].m) {
		ans[l] = 'M';
        if (dfs(node[now].m, x, l+1)) return 1;
	}
	return 0;
}
int main() {
	int __; cin >> __;
	while(__--) {
		int n; cin >> n;
		for (int i = 1, a, b, c; i<=n/2; ++i) {
			scanf("%d%d%d",  &a, &b, &c);
			node[a].f = b, node[a].m = c;
		}
		int m; cin >> m;
		for (int i = 1, a, b; i<=m; ++i) {
			scanf("%d%d", &a, &b);
			if (dfs(a, b, 0)) {
				cout << 1 << ' ' << ans << endl;
			}
			else if (dfs(b, a, 0)) {
				cout << 0 << ' ' << ans << endl;
			}
			else cout << "Relative" << endl;
		}
		clr(node, 0);
	}
	return 0;
} 
原文地址:https://www.cnblogs.com/shuitiangong/p/14420258.html