QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184609#5672. Connectivity ProblemSayedHassan#ML 0ms0kbC++14637b2023-09-20 22:35:252023-09-20 22:35:26

Judging History

你现在查看的是最新测评结果

  • [2023-09-20 22:35:26]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-09-20 22:35:25]
  • 提交

answer

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=1005;
int p[N],sz[N];
int find(int u)
{
    if(p[u]!=u)return p[u]=find(p[u]);
}
bool merge(int u,int v)
{
    u=find(u),v=find(v);
    if(u==v)return true;
    if(sz[u]<sz[v])swap(u,v);
    p[v]=u;
    sz[u]+=sz[v];
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    fill(sz,sz+N,1);
    iota(p,p+N,0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        cout<<(merge(u,v)?"Y":"N")<<'\n';
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

12
3 4
4 9
8 1
2 3
5 6
2 9
5 9
7 3
4 8
5 6
1 8
6 1

output:


result: