QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690088#7755. Game on a ForestsunnygreenWA 3ms11040kbC++142.5kb2024-10-30 20:13:372024-10-30 20:13:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 20:13:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11040kb
  • [2024-10-30 20:13:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define se second
#define mk make_pair
#define eb emplace_back
#define rep(i,l,r) for(int i=(l); i<=(r); ++i)
#define rep_(i,l,r) for(int i=(l); i>=(r); --i)
typedef long long lr;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr db pi=3.141592653589793,eps=1e-9;
constexpr int inf32=0x3f3f3f3f,Inf32=0xc0c0c0c0;
constexpr lr inf64=0x3f3f3f3f3f3f3f3f,Inf64=0xc0c0c0c0c0c0c0c0;
template<typename T>il T Max(T x,T y) { return (x>y)? x:y; }
template<typename T>il T Min(T x,T y) { return (x<y)? x:y; }
template<typename T>il T gcd(T x,T y) { return (!y)? x:gcd(y,x%y); }
template<typename T>il T Abs(T x) { return (x>0)? x:(-x); }
template<typename T>il T Rnd(T l,T r,mt19937_64 &eng)
{
	uniform_int_distribution<T> uid(l,r);
	return uid(eng);
}
mt19937_64 eng(chrono::high_resolution_clock::now().time_since_epoch().count());
constexpr int N=100100;
int n,m,x[N],y[N],siz[N],fa[N],sz[N],val1[N],val2[N]; vi v[N],w[N];
bool vis[N];
il int calc(int _) { return (_&1)? 1:2; }
il int Find(int _) { return (fa[_]==_)? _:fa[_]=Find(fa[_]); }
il void Merge(int X,int Y) { (sz[X]<sz[Y])? (fa[X]=Y,sz[Y]+=sz[X]):(fa[Y]=X,sz[X]+=sz[Y]); }
il void dfs(int u,int fa)
{
	vis[u]=1,siz[u]=1;
	for(int to:v[u])
		if(y[to]!=fa)
			dfs(y[to],u),siz[u]+=siz[y[to]];
	for(int to:w[u])
		if(x[to]!=fa)
			dfs(x[to],u),siz[u]+=siz[x[to]];
}
il void dfs2(int u,int fa,int rt)
{
	val1[u]=calc(siz[rt])^calc(siz[rt]-siz[u]);
	for(int to:v[u])
		if(y[to]!=fa)
			val1[u]^=calc(siz[y[to]]),val2[to]=calc(siz[rt])^calc(siz[rt]-siz[y[to]])^calc(siz[y[to]]),dfs2(y[to],u,rt);
	for(int to:w[u])
		if(x[to]!=fa)
			val1[u]^=calc(siz[x[to]]),val2[to]=calc(siz[rt])^calc(siz[rt]-siz[x[to]])^calc(siz[x[to]]),dfs2(x[to],u,rt);
}
il void Solve()
{
	cin>>n>>m;
	rep(i,1,n)
		fa[i]=i,sz[i]=1;
	rep(i,1,m)
	{
		cin>>x[i]>>y[i],Merge(Find(x[i]),Find(y[i]));
		v[x[i]].eb(i),w[y[i]].eb(i);
	}
	rep(i,1,n)
		if(!vis[i])
			dfs(i,0),dfs2(i,0,i);
	int bp=0;
	rep(i,1,n)
		if(Find(i)==i)
			bp^=calc(sz[i]);
	int ans=0;
	rep(i,1,n)
		if(!(bp^val1[i]))
			++ans;
	rep(i,1,m)
		if(!(bp^val2[i]))
			++ans;
	cout<<ans<<'\n';
}
int main()
{
#ifdef LOCAL
	string fpre="test",isuf="in",osuf="out";
	assert(freopen((fpre+"."+isuf).c_str(),"r",stdin));
	assert(freopen((fpre+"."+osuf).c_str(),"w",stdout));
#endif
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T=1;
	while(T--)
		Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9148kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 10880kb

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 3ms
memory: 11040kb

input:

100000 1
4647 17816

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 10264kb

input:

100000 2
64075 72287
63658 66936

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 0ms
memory: 10452kb

input:

100000 3
59930 72281
31689 59132
20469 33165

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 0ms
memory: 10852kb

input:

100000 10
20391 78923
27822 80617
21749 25732
12929 79693
42889 52515
59064 99869
29031 41875
4463 17813
13407 42498
19120 20957

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 10856kb

input:

99999 101
34378 94161
67696 83255
24557 25591
11476 58475
5684 38157
33843 35321
9046 24028
14293 77681
587 42098
9402 27228
6999 13980
27118 84005
3622 8353
13545 51621
16998 63647
32912 53178
15206 15815
56517 86335
5563 93770
153 278
11242 41753
75098 76792
1695 22836
25936 33352
2765 6778
19597 ...

output:

99898

result:

wrong answer 1st numbers differ - expected: '200', found: '99898'