이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,a[3009][3009],p[3009],sz[3009],c[3009],o,op,t;
ll gp(ll z)
{
if(p[z]==z)
return z;
return p[z]=gp(p[z]);
}
void mrg(ll x,ll y)
{
x=gp(x),y=gp(y);
if(x==y)
return;
if(sz[y]>sz[x])
swap(x,y);
p[y]=x;
sz[x]+=sz[y];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
scanf("%d%d",&t,&n);
for(ll i=1; i<=n; i++)
p[i]=i,sz[i]=1;
for(ll i=1; i<=n; i++)
for(ll j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==1)
mrg(i,j);
}
for(ll i=1; i<=n; i++)
{
if(c[gp(i)]==0)
c[gp(i)]=++o;
printf("%d ",c[gp(i)]);
}
printf("\n");
op=gp(1);
for(ll i=1; i<=n; i++)
{
if(i!=gp(i))
printf("%d %d\n",i,gp(i));
else if(i!=op)
printf("%d %d\n",i,op);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
izlet.cpp: In function 'int main()':
izlet.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d",&t,&n);
| ~~~~~^~~~~~~~~~~~~~
izlet.cpp:33:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d",&a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |