Submission #3499

# Submission time Handle Problem Language Result Execution time Memory
3499 2013-08-31T06:12:16 Z Apple_Cplus Cactus? Not cactus? (kriii1_C) C++
1 / 1
76 ms 12320 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 
 
int n,m;
vi v[100005];
int dep[100005];
int P[100005];
int cy[100005];
bool ck[100005];

void go(int x,int p,int D){
	ck[x]=1;
	dep[x]=D;
	P[x]=p;
	for(int i=0;i<v[x].size();i++){
		int t=v[x][i];

		if(t==p)continue;
		if(ck[t])continue;

		go(t,x,D+1);
	}
}
void END(){cout<<"Not cactus"<<endl;exit(0);}
void calc(int a,int b){
	int D=min(dep[a],dep[b]);
	
	while(dep[a]>D){
		if(++cy[a]==2)END();
		a=P[a];
	}
	while(dep[b]>D){
		if(++cy[b]==2)END();
		b=P[b];
	}
	while(a!=b){
		if(++cy[a]==2)END();
		if(++cy[b]==2)END();
		a=P[a];b=P[b];
	}
	if(++cy[a]==2)END();

}
void dfs(int x,int p){
	ck[x]=1;
	for(int i=0;i<v[x].size();i++){
		int t=v[x][i];if(t==p)continue;
		if(ck[t]){
			if(t<x)calc(t,x);
			continue;
		}

		dfs(t,x);
	}
}
int main(){
	scanf("%d%d",&n,&m);

	for(int i=0;i<m;i++){
		int s,e;scanf("%d%d",&s,&e);
		v[s].pb(e);v[e].pb(s);

	}

	go(1,-1,0);
	memset(ck,0,sizeof(ck));
	dfs(1,-1);
	cout<<"Cactus"<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5284 KB Output is correct
2 Correct 0 ms 5284 KB Output is correct
3 Correct 0 ms 5416 KB Output is correct
4 Correct 0 ms 5284 KB Output is correct
5 Correct 0 ms 5284 KB Output is correct
6 Correct 0 ms 5416 KB Output is correct
7 Correct 0 ms 5416 KB Output is correct
8 Correct 4 ms 5416 KB Output is correct
9 Correct 0 ms 5416 KB Output is correct
10 Correct 44 ms 8188 KB Output is correct
11 Correct 24 ms 8036 KB Output is correct
12 Correct 40 ms 9380 KB Output is correct
13 Correct 52 ms 8688 KB Output is correct
14 Correct 48 ms 8488 KB Output is correct
15 Correct 60 ms 10300 KB Output is correct
16 Correct 48 ms 8620 KB Output is correct
17 Correct 44 ms 9452 KB Output is correct
18 Correct 68 ms 11536 KB Output is correct
19 Correct 76 ms 12320 KB Output is correct
20 Correct 44 ms 8936 KB Output is correct
21 Correct 68 ms 8676 KB Output is correct
22 Correct 68 ms 10724 KB Output is correct
23 Correct 0 ms 5284 KB Output is correct
24 Correct 0 ms 5284 KB Output is correct
25 Correct 0 ms 5784 KB Output is correct
26 Correct 60 ms 8056 KB Output is correct
27 Correct 20 ms 6340 KB Output is correct
28 Correct 36 ms 7660 KB Output is correct
29 Correct 48 ms 7660 KB Output is correct
30 Correct 48 ms 7792 KB Output is correct
31 Correct 40 ms 7660 KB Output is correct
32 Correct 68 ms 8056 KB Output is correct
33 Correct 72 ms 8056 KB Output is correct
34 Correct 60 ms 8056 KB Output is correct