背模板直接AC,没有任何坑点。

#include<iostream>
#include<cstring>
using namespace std;
int n,m,k,que[105],map[105][105];
int getf(int k)
{
    return que[k]==k?k:que[k]=getf(que[k]);
}
int merge(int a,int b)
{
    if (getf(a)!=getf(b))
    que[getf(a)]=getf(b);
}
int main()
{
    int i,j,a,b,c;
    for (i=0;i<105;i++)
    que[i]=i;
    cin>>n>>m>>k;
    for (i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        map[a][b]=c;
        map[b][a]=c;
        if (c==1)
        merge(a,b);
    }
    for (i=0;i<k;i++)
    {
        cin>>a>>b;
        if (getf(a)==getf(b)&&map[a][b]!=-1)
        cout<<"No problem"<<endl;
        else if (getf(a)!=getf(b)&&map[a][b]!=-1)
        cout<<"OK"<<endl;
        else if (getf(a)==getf(b)&&map[a][b]==-1)
        cout<<"OK but..."<<endl;
        else if (getf(a)!=getf(b)&&map[a][b]==-1)
        cout<<"No way"<<endl;
    }
}