题目:https://www.patest.cn/contests/gplt/L2-010
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
//always online
int fa[maxn];
bool f[maxn][maxn];
int find(int x){
return fa[x]!=x?fa[x]=find(fa[x]):x;
}
void Union(int x,int y){
int a=find(x);
int b=find(y);
if(a==b)
return ;
fa[a]=b;
}
int main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
fa[i]=i; //
for(int i=0;i<m;i++){
int a,b,flg;
cin>>a>>b>>flg;
if(flg==1)
Union(a,b);
else
f[a][b]=f[b][a]=1;
}
for(int i=0;i<k;i++){
int a,b,flg=0;
cin>>a>>b;
if(find(a)==find(b)) flg=1;
if(flg&&!f[a][b])
cout<<"No problem"<<endl;
else if(!flg&&!f[a][b])
cout<<"OK"<<endl;
else if(flg&&f[a][b])
cout<<"OK but..."<<endl;
else
cout<<"No way"<<endl;
}
return 0;
}