# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3930 | wurikiji | Cactus? Not cactus? (kriii1_C) | C++98 | 64 ms | 11816 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <stack>
using namespace std;
vector<int> node[100001];
vector<int> rv[100001];
bool chk[100001];
int group[100001];
int cnt[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;
group[x] = grp;
for(int i = 0 ;i < rv[x].size();i++)
{
if( !chk[rv[x][i]] ) {
cnt[rv[x][i]]++;
dfs2(rv[x][i]);
}
else if( group[rv[x][i]] == grp )
{
cnt[rv[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);
rv[b].push_back(a);
}
memset(chk,0,sizeof(chk));
for(int i = 1; i <= n;i++)
{
if( !chk[i] )
dfs(i);
}
memset(cnt,0,sizeof(cnt));
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);
grp++;
}
}
for(int i = 1 ;i <=n;i++)
{
if( cnt[i] > 1 )
{
printf("Not cactus\n");
return 0;
}
}
printf("Cactus\n");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |