#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <stack>
using namespace std;
vector<int> node[100001];
bool chk[100001];
int group[100001];
stack<int> st;
int ret;
int grp;
void dfs(int x)
{
chk[x] = true;
for(int i = 0 ;i < node[x].size();i++)
{
if( !chk[node[x][i]] )
dfs(node[x][i]);
}
st.push(x);
}
void dfs2(int x)
{
chk[x] = true;
for(int i = 0 ;i < node[x].size();i++)
{
group[node[x][i]]++;
if( !chk[node[x][i]] )
dfs2(node[x][i]);
}
}
int main(void){
int n, m;
scanf("%d %d",&n, &m);
for(int i = 0 ;i < m ;i++)
{
int a, b;
scanf("%d %d", &a, &b);
node[a].push_back(b);
}
memset(chk,0,sizeof(chk));
for(int i = 1; i <= n;i++)
{
if( !chk[i] )
dfs(i);
}
memset(group, 0, sizeof(group));
grp = 0;
memset(chk,0,sizeof(chk));
while(!st.empty()){
int next = st.top();
st.pop();
if(!chk[next])
{
dfs2(next);
}
}
for(int i = 1 ;i <=n;i++)
{
if( group[i] > 1 )
{
printf("Not cactus\n");
return 0;
}
}
printf("Cactus\n");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
4072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |