题目地址 L2-010 排座位 (25 分)

发现这几天随便跳的L2的题目都是简单算法模板题,都可以去写写
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ba, bb, relation, f[110], gx[110][110];

int find(int n) {
	if(f[n] == n)
		return n;
	else
		return f[f[n]]; 
}

void mix(int a,int b) {
	a = find(a);
	b = find(b);
	if(a != b)
		f[b] = a;
}
int main() {
	cin>>n>>m>>k;
	for(int i = 1; i <= n; i++)
		f[i] = i;
	for(int i = 1; i <= m; i++) {
		cin>>ba>>bb>>relation;
		gx[bb][ba] = gx[ba][bb] = relation;
		if(relation != -1) mix(ba,bb);
	}
	for(int i = 1; i<= k; i++) {
		cin>>ba>>bb;
		if(gx[ba][bb] == 1)
			cout<<"No problem"<<endl;
		else if(gx[ba][bb] == 0)
			cout<<"OK"<<endl;
		else if(gx[ba][bb] == -1 && find(ba) == find(bb)) 
			cout<<"OK but..."<<endl;
		else
			cout<<"No way"<<endl;
	}
	return 0;
}