Submission #20250

#TimeUsernameProblemLanguageResultExecution timeMemory
20250hongjun7Cactus? Not cactus? (kriii1_C)C++14
1 / 1
115 ms27 KiB
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 100005
int n, m, d[MAXN], res, up[MAXN];
vector <int> v[MAXN];
int f(int x, int par) {
	int cnt = 0, ret = d[x];
	up[x] = d[x];
	for (auto &y : v[x]) {
		if (y == par) continue;
		if (!d[y]) {
			d[y] = d[x] + 1;
			int u = f(y, x);
			ret = min(ret, u);
			if (u <= d[x]) cnt++;
		}
		else {
			if (d[y] < d[x]) cnt++;
			up[x] = min(up[x], d[y]);
		}
	}
	if (cnt >= 2) res = 0;
	ret = min(ret, up[x]);
	return ret;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int x, y; scanf("%d%d", &x, &y);
		v[x].emplace_back(y);
		v[y].emplace_back(x);
	}
	d[1] = res = 1;
	f(1, 0);
	if (res) puts("Cactus");
	else puts("Not cactus");
}

Compilation message (stderr)

C.cpp: In function 'int main()':
C.cpp:29:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
C.cpp:31:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...