# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
404256 | ftkbrian | Cactus? Not cactus? (kriii1_C) | C++14 | 2 ms | 2636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
///간단히 생각해보면 cactus는 전체에서 사이클이 하나여야 함을 알 수 있음
///tree에 역행간선 하나 존재시 cactus일 것
///dfsordering + 깊이 저장 후 역행 간선 개수 2개 이상인 정점 개수 찾기
ll n,m,dep[101010],chk;
vector<ll> V[101010];
void dfs(ll tar,ll p)
{
if(dep[tar]) return;
dep[tar] = dep[p]+1;
for(auto i : V[tar])
dfs(i,tar);
}
main()
{
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i = 0 ; i < m ; i++)
{
ll a,b; cin>>a>>b;
V[a].pb(b), V[b].pb(a);
}
dfs(1,1);
for(int i = 1 ; i <= n ; i++)
{
ll t = 0;
for(auto q : V[i])
if(dep[q] < dep[i]) t++;
if(t == 2) chk++;
else if(t > 2){ cout<<"Not cactus"; return 0; }
}
if(chk < 2) cout<<"Cactus";
else cout<<"Not cactus";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |