# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
3909 | BalloonCollector | Cactus? Not cactus? (kriii1_C) | C++98 | 72 ms | 12152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
using namespace std;
typedef pair <int, int> ii;
int ch[100002], p[100002], c[100002], che[100002];
vector <ii> v[100002];
int cycle = 0;
void dfs(int u){
if( cycle ) return ;
ch[u] = 1;
int si = v[u].size();
// printf("%d\n", u);
for(int i=0; i<si; i++){
if( !che[v[u][i].second] ){
che[v[u][i].second] = 1;
if( !ch[v[u][i].first] ){
p[v[u][i].first] = u;
dfs( v[u][i].first );
}
else if( p[u] != v[u][i].first ){
int pos = u;
c[v[u][i].first] ++;
if( c[v[u][i].first] >= 2 ) {
cycle = 1;
return;
}
//printf("cycle %d \n", v[u][i]);
while( pos != v[u][i].first){
//printf("p %d \n", pos);
c[pos]++;
if( c[pos] >= 2 ){
cycle = 1;
//puts("");
return;
}
pos = p[pos];
}
//puts("");
}
}
}
}
int main(){ //freopen("input.txt", "r", stdin);
int n, m;
scanf("%d %d", &n, &m);
for(int i=0; i<m; i++){
int x, y;
scanf("%d %d", &x, &y);
v[x].push_back(ii(y, i));
v[y].push_back(ii(x, i));
}
dfs( 1 );
/*for(int i=1; i<=n; i++)
printf("%d ", c[i]);
puts("");*/
if( !cycle ) printf("Cactus\n");
else printf("Not cactus\n");
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |