Submission #16589

# Submission time Handle Problem Language Result Execution time Memory
16589 2015-08-29T02:11:30 Z gs14004 Cactus? Not cactus? (kriii1_C) C++14
1 / 1
72 ms 11180 KB
#include <cstdio>
#include <vector>
using namespace std;

bool ret = true;
bool colp[100005], vis[100005];
int par[100005];
vector<int> graph[100005];

void dfs(int x, int pa){
	vis[x] = 1;
	par[x] = pa;
	for(auto &i : graph[x]){
		if(i == pa) continue;
		if(!vis[i]) continue;
		int pos = x;
		while(1){		
			if(colp[pos]){
				ret = 0;
				break;		
			}
			colp[pos] = 1;
			if(pos == i) break;
			pos = par[pos];
		}
	}
	for(auto &i : graph[x]){
		if(i == pa) continue;
		if(vis[i]) continue;
		dfs(i, x);
	}
}

int main(){
	int n, m;
	scanf("%d %d",&n,&m);
	for(int i=0; i<m; i++){
		int u, v;
		scanf("%d %d",&u,&v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	dfs(1, 0);
	puts(ret ? "Cactus" : "Not cactus");
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4140 KB Output is correct
2 Correct 0 ms 4140 KB Output is correct
3 Correct 0 ms 4272 KB Output is correct
4 Correct 0 ms 4140 KB Output is correct
5 Correct 5 ms 4140 KB Output is correct
6 Correct 0 ms 4272 KB Output is correct
7 Correct 5 ms 4272 KB Output is correct
8 Correct 0 ms 4272 KB Output is correct
9 Correct 2 ms 4272 KB Output is correct
10 Correct 35 ms 7044 KB Output is correct
11 Correct 28 ms 6892 KB Output is correct
12 Correct 39 ms 8240 KB Output is correct
13 Correct 50 ms 7548 KB Output is correct
14 Correct 41 ms 7348 KB Output is correct
15 Correct 56 ms 9160 KB Output is correct
16 Correct 40 ms 7472 KB Output is correct
17 Correct 38 ms 8308 KB Output is correct
18 Correct 43 ms 10388 KB Output is correct
19 Correct 59 ms 11180 KB Output is correct
20 Correct 32 ms 7788 KB Output is correct
21 Correct 45 ms 7528 KB Output is correct
22 Correct 57 ms 9576 KB Output is correct
23 Correct 0 ms 4140 KB Output is correct
24 Correct 0 ms 4140 KB Output is correct
25 Correct 3 ms 4636 KB Output is correct
26 Correct 41 ms 6912 KB Output is correct
27 Correct 22 ms 5196 KB Output is correct
28 Correct 39 ms 6516 KB Output is correct
29 Correct 72 ms 6516 KB Output is correct
30 Correct 55 ms 6648 KB Output is correct
31 Correct 33 ms 6516 KB Output is correct
32 Correct 46 ms 6912 KB Output is correct
33 Correct 45 ms 6912 KB Output is correct
34 Correct 38 ms 6912 KB Output is correct