답안 #527673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527673 2022-02-18T01:58:33 Z siewjh Potemkin cycle (CEOI15_indcyc) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 1005, MAXR = 200'005;
int adjmat[MAXN][MAXN];
int vis[MAXR], p[MAXR];
pair<int, int> elist[MAXR];
vector<int> oadjlist[MAXN], adjlist[MAXR];
bool ans_found = 0;
void dfs(int x, int par) {
	if (ans_found) return;
	vis[x] = 2;
	p[x] = par;
	for (int nxt : adjlist[x]) {
		if (!vis[nxt]) dfs(nxt, x);
		else if (vis[nxt] == 2 && !ans_found) {
			ans_found = 1;
			for (int curr = x; curr != nxt; curr = p[curr]) cout << elist[curr].first << ' ';
			cout << elist[nxt].first;
		}
		if (ans_found) return;
	}
	vis[x] = 1; // not useful anymore
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int nodes, edges; cin >> nodes >> edges;
	memset(adjmat, -1, sizeof(adjmat));
	for (int i = 0; i < edges; i++) {
		int a, b; cin >> a >> b;
		elist[i] = { a, b }; elist[i + edges] = { b, a };
		adjmat[a][b] = i; adjmat[b][a] = i + edges;
		oadjlist[a].push_back(b); oadjlist[b].push_back(a);
	}
	for (int i = 1; i <= nodes; i++) {
		int sz = oadjlist[i].size();
		for (int j = 0; j < sz; j++)
			for (int k = 0; k < j; k++) {
				int a = oadjlist[i][j], b = oadjlist[i][k];
				if (adjmat[a][b] == -1) {
					adjlist[adjmat[a][i]].push_back(adjmat[i][b]);
					adjlist[adjmat[b][i]].push_back(adjmat[i][a]);
				}
			}
	}
	for (int i = 0; i < edges * 2; i++)
		if (!vis[i])
			dfs(i, -1);
	if (!ans_found) cout << "no";
	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:29:2: error: 'memset' was not declared in this scope
   29 |  memset(adjmat, -1, sizeof(adjmat));
      |  ^~~~~~
indcyc.cpp:3:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    2 | #include <vector>
  +++ |+#include <cstring>
    3 | using namespace std;