Time Limit: 1000MS Memory Limit: 65536KB
某屆電影節評選電影,共有兩部電影進入最后評選環節,有n名觀眾,每個人有一次投票的機會,每個人都按照規則投給其中一部電影。為了了解情況,記者隨機詢問了一些人,一共詢問了m次,特別神奇的是,記者每次都詢問兩個人,而且這兩個人都把票投給了同一部電影,觀眾編號為1~n。
Input
多組輸入,每組第一行是兩個整數n,m (2 <= n <=100000,0 <= m < n/2),接下來m行數據,表示m次詢問,每行數據有兩個整數a,b代表觀眾的編號(1 <= a,b <= n),觀眾a和觀眾b投票給了同一部電影,接下來一行是兩個整數c,d(1 <= c,d <= n)。
Output
對于每一組輸入,輸出一行,如果觀眾c和觀眾d投票給同一部電影,輸出”same”,如果不能確定,輸出”not sure”。
Example Input
5 2 1 2 2 3 1 3 5 2 1 2 3 4 1 4 5 2 1 2 3 4 2 5
Example Output
same not sure not sure
Hint
本題似乎與 SDUT 3386 小雷的冰茶幾 http://blog.csdn.net/yxc9806/article/details/56035744 沒有任何區別???exm?
Submit
#include <bits/stdc++.h>using namespace std;const int MAXN = 100010;int par[MAXN], high[MAXN];int Find(int x){ if(par[x] == x) return x; return par[x] = Find(par[x]);}void unite(int x, int y){ x = Find(x); y = Find(y); if(x == y) return ; if(high[x] < high[y]) par[x] = y; else { par[y] = x; if(high[x] == high[y]) high[x]++; }}int main(){ int i, N, k; while(~scanf("%d %d", &N, &k)) { for(i = 1; i <= N; i++) par[i] = i; memset(high, 0, sizeof(high)); for(i = 0; i < k; i++) { int x, y; scanf("%d %d", &x, &y); unite(x, y); } int c, d; scanf("%d %d", &c, &d); if(Find(c) == Find(d)) printf("same/n"); else printf("not sure/n"); } return 0;}
|
新聞熱點
疑難解答