답안 #1034711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034711 2024-07-25T17:01:03 Z vjudge1 Pipes (CEOI15_pipes) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define vt vector
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T> bool chmin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool chmax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());


//#pragma GCC optimize("O3,unroll-loops")


/**
 * Author: Lukas Polacek
 * Date: 2009-10-26
 * License: CC0
 * Source: folklore
 * Description: Disjoint-set data structure.
 * Time: $O(\alpha(N))$
 */
const int N = 30'010;
namespace d1 {
	int e[N];
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool sameSet(int a, int b) { return find(a) == find(b); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
		return true;
	}
};
namespace d2 {
	int e[N];
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool sameSet(int a, int b) { return find(a) == find(b); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
		return true;
	}
};
vt<int> g[N+1];
int low[N+1], id[N+1], par[N=1];
int timer=0;
void dfs(int at) {
	bool ck=0;
	id[at]=low[at]=++timer;
	for(int to:g[at]) {
		if(to == par[at] and ck==0) {
			ck=1;
			continue;
		}
		if(id[to]) {
			low[at]=min(low[at], id[to]);		
		} else {
			par[to]=at;
			dfs(to);
			low[at]=min(low[at], low[to]);
		}
	}
	if(low[at] == id[at] and at!=par) {
		cout << at << " " << par << "\n";
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	int n, m;
	cin >> n >> m;
	int u, v;
	int cnt=0;
	memset(d1::e, -1, sizeof d1::e);
	memset(d2::e, -1, sizeof d2::e);
	rep(i, 0, m) {
		cin >> u >> v;
		if(d1::join(u, v) || d2::join(u, v)) {
			g[u].pb(v);
			g[v].pb(u);
		}
	}
	for(int i= 1;i<=n;i++) {
		if(!id[i])
			dfs(i);
	}
}

Compilation message

pipes.cpp:62:29: error: assignment of read-only variable 'N'
   62 | int low[N+1], id[N+1], par[N=1];
      |                            ~^~
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:68:12: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   68 |   if(to == par[at] and ck==0) {
      |            ^~~
      |            __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
pipes.cpp:75:4: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   75 |    par[to]=at;
      |    ^~~
      |    __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
pipes.cpp:80:31: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   80 |  if(low[at] == id[at] and at!=par) {
      |                               ^~~
      |                               __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
pipes.cpp: In function 'int main()':
pipes.cpp:90:6: warning: unused variable 'cnt' [-Wunused-variable]
   90 |  int cnt=0;
      |      ^~~