| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 3714 | arine | Cactus? Not cactus? (kriii1_C) | C++98 | 28 ms | 1868 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#define MAX_V 100005
using namespace std;
int V, E;
int parent[MAX_V];
int notMSTEdge[MAX_V];
int find(int target) {
if(parent[target]==target) return target;
return (parent[target]=find(parent[target]));
}
void unify(int a, int b) {
int roota=find(a), rootb=find(b);
parent[roota]=rootb;
}
int main() {
scanf("%d %d", &V, &E);
for(int i=0; i<V; ++i) parent[i]=i, notMSTEdge[i]=0;
int a, b;
for(int i=0; i<E; ++i) {
scanf("%d %d", &a, &b);
--a, --b;
int roota=find(a), rootb=find(b);
if(roota==rootb) {
++notMSTEdge[a], ++notMSTEdge[b];
} else {
unify(a, b);
}
}
for(int i=0; i<V; ++i)
if(notMSTEdge[i]>=2) {
printf("Not cactus");
return 0;
}
printf("Cactus");
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
