QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322508 | #4571. Even Split | bobbilyking | Compile Error | / | / | C++20 | 2.4kb | 2024-02-07 08:28:05 | 2024-02-07 08:28:05 |
Judging History
answer
this algorithm is just big brain, much better impl of what i had in mind and still dont fully understand the "son" thing, but the general principle is cool.
just stare at invariants harder i guess to get better at algo design :/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=101000;
int n,m,comp[N],par[N],sz[N],cnt,ins[N],vis[N];
VI e[N],son[N],ans[N];
void del(int u) {
assert(comp[u] == 0);
assert(vis[u]);
++cnt;
function<void(int)> dfs=[&](int u) {
comp[u]=cnt;
ans[cnt].pb(u);
// wth is son array?
for (auto v:son[u]) if (comp[v]==0) {
dfs(v);
}
};
dfs(u);
}
void dfs(int u) {
ins[u]=1;
vis[u]=1;
for (auto v:e[u]) {
if (!vis[v]) {
son[u].pb(v);
par[v]=u;
dfs(v);
if (comp[v]==0) sz[u]^=1;
} else if (!ins[v]&&comp[v]==0) {
// we've already processed this size in the dfs,
// but when removing components size doesn't change
// unless ur the intermediate nodes on the path,
// which do change, but we're deleting them all already so :/
assert(sz[v] == 1);
// if we visited it and it's not in a component, it must be "finalized" to have odd size,
// and all its parents must be "finalized" to have odd size.
comp[v]=-1;
int w=par[v];
while (w!=u) {
del(w);
w=par[w];
}
son[u].pb(v);
par[v]=u;
comp[v]=0;
}
}
sz[u]^=1;
if (sz[u]==0) {
del(u);
}
ins[u]=0;
}
int main() {
scanf("%d%d",&n,&m);
rep(i,0,m) {
int u,v;
scanf("%d%d",&u,&v);
e[u].pb(v);
e[v].pb(u);
}
dfs(0);
printf("%d\n",cnt);
rep(i,1,cnt+1) {
printf("%d",SZ(ans[i]));
for (auto u:ans[i]) printf(" %d",u);
puts("");
}
}
详细
answer.code:1:1: error: expected unqualified-id before ‘this’ 1 | this algorithm is just big brain, much better impl of what i had in mind and still dont fully understand the "son" thing, but the general principle is cool. | ^~~~ In file included from /usr/include/c++/13/bits/stl_algobase.h:62, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:5: /usr/include/c++/13/ext/type_traits.h:164:35: error: ‘constexpr const bool __gnu_cxx::__is_null_pointer’ redeclared as different kind of entity 164 | __is_null_pointer(std::nullptr_t) | ^ /usr/include/c++/13/ext/type_traits.h:159:5: note: previous declaration ‘template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)’ 159 | __is_null_pointer(_Type) | ^~~~~~~~~~~~~~~~~ /usr/include/c++/13/ext/type_traits.h:164:26: error: ‘nullptr_t’ is not a member of ‘std’; did you mean ‘nullptr_t’? 164 | __is_null_pointer(std::nullptr_t) | ^~~~~~~~~ In file included from /usr/include/c++/13/cstddef:50, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:41: /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:443:29: note: ‘nullptr_t’ declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ In file included from /usr/include/c++/13/bits/stl_pair.h:60, from /usr/include/c++/13/bits/stl_algobase.h:64: /usr/include/c++/13/type_traits:510:26: error: ‘std::size_t’ has not been declared 510 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/13/type_traits:511:25: error: ‘_Size’ was not declared in this scope 511 | struct is_array<_Tp[_Size]> | ^~~~~ /usr/include/c++/13/type_traits:511:31: error: template argument 1 is invalid 511 | struct is_array<_Tp[_Size]> | ^ /usr/include/c++/13/type_traits:617:33: error: ‘nullptr_t’ is not a member of ‘std’; did you mean ‘nullptr_t’? 617 | struct is_null_pointer<std::nullptr_t> | ^~~~~~~~~ /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:443:29: note: ‘nullptr_t’ declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ /usr/include/c++/13/type_traits:617:42: error: template argument 1 is invalid 617 | struct is_null_pointer<std::nullptr_t> | ^ /usr/include/c++/13/type_traits:621:48: error: template argument 1 is invalid 621 | struct is_null_pointer<const std::nullptr_t> | ^ /usr/include/c++/13/type_traits:625:51: error: template argument 1 is invalid 625 | struct is_null_pointer<volatile std::nullptr_t> | ^ /usr/include/c++/13/type_traits:629:57: error: template argument 1 is invalid 629 | struct is_null_pointer<const volatile std::nullptr_t> | ^ /usr/include/c++/13/type_traits:1348:37: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’? 1348 | : public integral_constant<std::size_t, alignof(_Tp)> | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:214:23: note: ‘size_t’ declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/13/type_traits:1348:57: error: template argument 1 is invalid 1348 | : public integral_constant<std::size_t, alignof(_Tp)> | ^ /usr/include/c++/13/type_traits:1357:37: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’? 1357 | : public integral_constant<std::size_t, 0> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:214:23: note: ‘size_t’ declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/13/type_traits:1357:46: error: template argument 1 is invalid 1357 | : public integral_constant<std::size_t, 0> { }; | ^ /usr/include/c++/13/type_traits:1359:26: error: ‘std::size_t’ has not been declared 1359 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/13/type_traits:1360:21: error: ‘_Size’ was not declared in this scope 1360 | struct rank<_Tp[_Size]> | ^~~~~ /usr/include/c++/13/type_traits:1360:27: error: template argument 1 is invalid 1360 | struct rank<_Tp[_Size]> | ^ /usr/include/c++/13/type_traits:1361:37: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’? 1361 |...