标签:
Description
Input
Output
Sample Input
3 3
0 > 1
1 < 2
0 > 2
4 4
1 = 2
1 > 3
2 > 0
0 > 1
3 3
1 > 0
1 > 2
2 < 1
Sample Output
OK
CONFLICT
UNCERTAIN
--------------------------------------------------我是分割线^_^-------------------------------------------------------------
这道题也是WA不少次了,我是事后看题解才反应过来,很无语的一道题,要先全部接受输入把等号处理
掉,我之前一边输入一边处理等号,TLE到凌晨才发现= =,主要就是先用并查集把相等的元素全部合并
然后当作一个数处理,然后就是一个拓扑排序。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define Int __int64
#define INF 0x3f3f3f3f
const int MAXN = 22222;
int team[MAXN];
int head[MAXN];
int point[MAXN];
int nxt[MAXN];
int edgecnt;
int ingrade[MAXN];
int n, m;
int road[MAXN];
int sum;
int A[MAXN], B[MAXN];
char op[MAXN];
void ini() {
memset(head, -1, sizeof(head));
memset(ingrade, 0, sizeof(ingrade));
edgecnt = 0;
sum = n;
for (int i = 0; i < n; i++) {
road[i] = i;
}
}
void Add_Edge(int u, int v) {
nxt[edgecnt] = head[u];
point[edgecnt] = v;
head[u] = edgecnt++;
}
int FindRoot(int rt) {
return road[rt] == rt ? rt : (road[rt] = FindRoot(road[rt]));
}
int main()
{
//freopen("input.txt", "r", stdin);
while (scanf("%d %d\n", &n, &m) != EOF) {
ini();
for (int i = 0; i < m; i++) {
scanf("%d %c %d", &A[i], &op[i], &B[i]);
if (op[i] == ‘=‘) {
int root1 = FindRoot(A[i]);
int root2 = FindRoot(B[i]);
if (root1 != root2) {
road[root2] = root1;
sum--;//记得合并之后减一,这才是当前的集合个数
}
}
}
for (int i = 0; i < m; i++) {
if (op[i] == ‘=‘) {
continue;
}
int a = A[i