好吧,是我想太多了
输入样例:
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
#include <iostream>
#include <string>
using namespace std;
int person[101][101] = { 0 };
int n, m, k;
int find(int c, int d)
{
for (int i = 1; i <= n; i++)
if (person[c][i] && person[d][i]) return 1;
return 0;
}
int main()
{
cin >> n >> m >> k;
int x, y, z;
for (int i = 0; i < m; i++)
{
cin >> x >> y >> z;
person[x][y] = z;
person[y][x] = z;
}
for (int i = 0; i < k; i++)
{
cin >> x >> y;
if (person[x][y] == 1) cout << "No problem" << endl;
else if (person[x][y] == 0) cout << "OK" << endl;
else if (person[x][y] == -1 && find(x, y)) cout << "OK but..." << endl;
else cout << "No way" << endl;
}
return 0;
}