输入样例:
7 8 4
5 6 1
2 7 -1
1 3 1
3 4 1
6 7 -1
1 2 1
1 4 1
2 3 -1
3 4
5 7
2 3
7 2
输出样例:
No problem
OK
OK but...
No way
为啥要写这题呢,纯纯是脑子有问题,当时卡了好久不知道哪有问题,因为朋友的朋友是朋友(当时一看直接脑袋爆炸,要是数据量大一点直接爆炸),然后忘记a b里面的朋友也要添加上彼此的朋友了
#include "bits/stdc++.h"
using namespace std;
set<int> s[200], t[200];
int main(){
int n, m, k;
cin>>n>>m>>k;
int a, b, c;
while(m--){
cin>>a>>b>>c;
if(c == 1){
s[a].insert(b);
s[b].insert(a);
for(auto i : s[b]){
s[a].insert(i);
}
for(auto i : s[a]){
for(auto j : s[a]){
s[i].insert(j);
}
}
}
else if (c == -1){
t[a].insert(b);
t[b].insert(a);
}
}
while(k--){
cin>>a>>b;
if(t[a].find(b) != t[a].end()){
if(s[a].find(b) != s[a].end() ||s[b].find(a) != s[b].end()) cout<<"OK but...";
else cout<<"No way";
}
else if(s[a].find(b) != s[a].end()||s[b].find(a) != s[b].end()) cout<<"No problem";
else cout<<"OK";
if(k != 0) cout<<endl;
}
return 0;
}