# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
3598 | movie_jo | Cactus? Not cactus? (kriii1_C) | C11 | 28 ms | 2260 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
int x[100001];
int group[100001], gl = 1;
int cycle[100001];
int main(void)
{
int N, M, i, a, b, y, z, chk = 0;
scanf("%d %d", &N, &M);
for(i = 0; i < M; i++)
{
scanf("%d %d", &a, &b);
if(chk)
continue;
if(x[a])
{
if(x[b])
{
y = x[a];
z = x[b];
while(group[y] != y)
y = group[y];
while(group[z] != z)
z = group[z];
if(y == z)
{
cycle[y]++;
if(cycle[y] > 1)
chk = 1;
}
else
{
if(y > z)
{
group[y] = z;
group[x[a]] = z;
}
else
{
group[z] = y;
group[x[b]] = y;
}
}
}
else
{
x[b] = x[a];
}
}
else if(x[b])
{
x[a] = x[b];
}
else
{
x[a] = gl;
x[b] = gl;
group[gl] = gl;
gl++;
}
}
printf("%sactus\n", chk?"Not c":"C");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |