# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
5125 | ainta | Cactus? Not cactus? (kriii1_C) | C++98 | 92 ms | 10088 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<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int par[100010], C, chk[100010];
vector<int>E[100010];
bool v[100010];
int n;
void DFS(int a){
v[a] = true;
int i, x;
for (i = 0; i < E[a].size(); i++){
if (v[E[a][i]] && E[a][i] != par[a]){
x = a;
while (x != E[a][i]){
chk[x]++;
x = par[x];
}
chk[x]++;
}
}
for (i = 0; i < E[a].size(); i++){
if (!v[E[a][i]]){
par[E[a][i]] = a;
DFS(E[a][i]);
}
}
}
int main(){
int i, a, b, m;
scanf("%d%d", &n, &m);
while (m--){
scanf("%d%d", &a, &b);
E[a].push_back(b);
E[b].push_back(a);
}
DFS(1);
for (i = 1; i <= n; i++)if (chk[i] >= 2)break;
printf(i != n + 1 ? "Not Cactus\n" : "Cactus\n");
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |