电影节

Time Limit: 1000MS MemoryLimit: 65536KB

SubmitStatistic

ProblemDescription

某届电影节评选电影,共有两部电影进入最后评选环节,有n名观众,每个人有一次投票的机会,每个人都按照规则投给其中一部电影。为了了解情况,记者随机询问了一些人,一共询问了m次,特别神奇的是,记者每次都询问两个人,而且这两个人都把票投给了同一部电影,观众编号为1~n

Input

多组输入,每组第一行是两个整数nm (2 <= n <=1000000 <= m < n/2),接下来m行数据,表示m次询问,每行数据有两个整数ab代表观众的编号(1 <= ab <= n),观众a和观众b投票给了同一部电影,接下来一行是两个整数cd(1 <= cd <= n)

Output

对于每一组输入,输出一行,如果观众c和观众d投票给同一部电影,输出”same”,如果不能确定,输出”not sure”

ExampleInput

5 2

1 2

2 3

1 3

5 2

1 2

3 4

1 4

5 2

1 2

3 4

2 5

ExampleOutput

same

not sure

not sure

Hint

 

Author

xj

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int f[102000]={0},n,m,k,sum;
int getf(int v)
{
    if(f[v]==v)
    {
        return v;
    }
    else
    {
        f[v] = getf(f[v]);
        return f[v];
    }
}
void amerge(int l,int r)
{
    int t1,t2;
    t1 = getf(l);
    t2 = getf(r);
    if(t1!=t2)
    {
        f[t2] = t1;
    }
    return ;
}
int main()
{
    int x,y,i;
    while(~scanf("%d%d",&n,&m))
    {
        for(i=1;i<=n;i++)
        {
            f[i] = i;
        }
        for(i=1;i<=m;i++)
        {
            scanf("%d%d",&x,&y);
            amerge(x,y);
        }
        sum = 0;
        /*for(i = 1;i<=n;i++)
        {
            if(f[i]==i)
            {
            sum++;
            }
        }
        printf("%d\n",sum);*/
        int c,d;
        scanf("%d%d",&c,&d);
        if(getf(c)==getf(d))
        {
            printf("same\n");
        }
        else
        {
            printf("not sure\n");
        }
    }
    return 0;
}



/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 164ms
Take Memory: 268KB
Submit time: 2017-02-17 10:32:08
****************************************************/