1. 程式人生 > 實用技巧 >7-10 排座位 (25分)

7-10 排座位 (25分)

7-10排座位(25分)

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<stack>
using namespace std;
#define STDIN freopen("in.in", "r", stdin);freopen("out.out", "w", stdout);


const
int N = 105; int n, m, k; int fa[N]; set<int> se[N]; void init() { for (int i = 1; i <= n; i++) fa[i] = i; } int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } void unite(int a, int b) { int fa1 = find(a); int fb = find(b); fa[fa1] = fb; } int main() {
// STDIN cin >> n >> m >> k; init(); int a, b, c; while (m--) { cin >> a >> b >> c; if (c == 1) { unite(a, b); } if (c == -1) { se[a].insert(b), se[b].insert(a); } }
for (int i = 1; i <= k; i++) { int a, b; cin >> a >> b; if (find(a) == find(b) && se[a].find(b) == se[a].end()) { puts("No problem"); } if (find(a) != find(b) && se[a].find(b) == se[a].end()) puts("OK"); if (se[a].find(b) != se[a].end() && find(a) == find(b)) puts("OK but..."); if (find(a) != find(b)&&se[a].find(b) != se[a].end()) puts("No way"); } }