# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
3798 | cki86201 | Cactus? Not cactus? (kriii1_C) | C++98 | 76 ms | 12172 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> edge[100000];
vector<int> now;
bool check[100000]={0};
bool check_cycle[100000]={0};
bool ans=false;
int distime[100000]={0},deltime[100000]={0},time=0;
void dfs(int a,int par){
check[a]=true;
distime[a]=time++;
now.push_back(a);
int i,j;
for(i=0;i<edge[a].size();i++){
if(check[edge[a][i]] && edge[a][i]!=par && distime[edge[a][i]]<distime[a]){
for(j=now.size()-1;j>=0;j--){
if(check_cycle[now[j]]){
ans=true;
return;
}
check_cycle[now[j]]=true;
if(now[j]==edge[a][i]) break;
}
}
else if(!check[edge[a][i]]){
dfs(edge[a][i],a);
if(ans) return;
}
}
deltime[a]=time++;
now.pop_back();
}
int main()
{
int i,n,m,a,b;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){
scanf("%d%d",&a,&b);
edge[a-1].push_back(b-1);
edge[b-1].push_back(a-1);
}
dfs(0,0);
if(ans) printf("Not cactus");
else printf("Cactus");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |