一道近乎裸并查集的题
需要注意的是保存敌对关系
#include <iostream>
using namespace std;
const int N = 107;
int root[N];
int G[N][N];
int find(int x){
if(x == root[x]) return x;
else return root[x] = find(root[x]);
}
int main(){
int n, m, k, u, v, st;
for(int i = 0; i < N; i++){
root[i] = i;
}
cin>>n>>m>>k;
while(m--){
cin>>u>>v>>st;
if(st == -1){
G[u][v] = -1;
G[v][u] = -1;
}else{
int a = find(u);
int b = find(v);
if(a != b) root[b] = a;
}
}
while(k--){
cin>>u>>v;
int a = find(u);
int b = find(v);
if(G[u][v] != -1 && a== b){
cout<<"No problem"<<endl;
}else if(G[u][v] != -1 && a != b){
cout<<"OK"<<endl;
}else if(G[u][v] == -1 && a == b){
cout<<"OK but..."<<endl;
}else if(G[u][v] == -1 && a != b){
cout<<"No way"<<endl;
}
}
return 0;
}