QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613208#7936. Eliminate TreeuukuWA 2ms10140kbC++143.9kb2024-10-05 13:45:152024-10-05 13:45:15

Judging History

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

  • [2024-10-05 13:45:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10140kb
  • [2024-10-05 13:45:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

namespace ModInt{
	template <uint32_t mod>
	struct mint
	{
		#define i32 int32_t
		#define u32 uint32_t
		#define u64 uint64_t
		static constexpr u32 get_r(){u32 ret=mod;for(i32 i=0;i<4;++i)ret*=2-mod*ret;return ret;}
		static constexpr u32 r=get_r();
		static const u32 n2=-u64(mod)%mod;
		static const u32 mod2=mod<<1;
		u32 a;
		constexpr mint():a(0){}
		constexpr mint(const int64_t &b):a(reduce(u64(b%mod+mod)*n2)){};
		static constexpr u32 reduce(const u64 &b){return (b+u64(u32(b)*u32(-r))*mod)>>32;}
		const mint &operator+=(const mint &b){if(i32(a+=b.a-mod2)<0)a+=mod2;return *this;}
		const mint &operator-=(const mint &b){if(i32(a-=b.a)<0)a+=mod2;return *this;}
		const mint &operator*=(const mint &b){a=reduce(u64(a)*b.a);return *this;}
		const mint &operator/=(const mint &b){*this*=b.inverse();return *this;}
		const mint operator+(const mint &b)const{return mint(*this)+=b;}
		const mint operator-(const mint &b)const{return mint(*this)-=b;}
		const mint operator*(const mint &b)const{return mint(*this)*=b;}
		const mint operator/(const mint &b)const{return mint(*this)/=b;}
		const bool operator==(const mint &b)const{return(a>=mod?a-mod:a)==(b.a>=mod?b.a-mod:b.a);}
		const bool operator!=(const mint &b)const{return(a>=mod?a-mod:a)!=(b.a>=mod?b.a-mod:b.a);}
		const mint operator-()const{return mint()-mint(*this);}
		const mint ksm(u64 n)const{mint ret(1);for(mint mul(*this);n;n>>=1,mul*=mul)if(n&1)ret*=mul;return ret;}
		const mint inverse()const{return ksm(mod-2);}
		friend ostream &operator<<(ostream &os, const mint &b){return os<<b.get();}
		friend istream &operator>>(istream &is, mint &b){int64_t t;is>>t;b=mint(t);return(is);}
		const u32 get()const{u32 ret=reduce(a);return ret>=mod?ret-mod:ret;}
		static const u32 get_mod(){return mod;}
	};
}
using namespace ModInt;

namespace FAST_IO{
	#define ll long long
	#define ull unsigned long long
	#define db double
	#define _8 __int128_t
	#define Get() (BUF[Pin++])
	const int LEN=1<<20;
	char BUF[LEN];
	int Pin=LEN;
	inline void flushin(){memcpy(BUF,BUF+Pin,LEN-Pin),fread(BUF+LEN-Pin,1,Pin,stdin),Pin=0;return;}
	inline char Getc(){return (Pin==LEN?(fread(BUF,1,LEN,stdin),Pin=0):0),BUF[Pin++];}
	template<typename tp>inline tp read(){(Pin+40>=LEN)?flushin():void();tp res=0;char f=1,ch=' ';for(;ch<'0'||ch>'9';ch=Get())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=Get())res=(res<<3)+(res<<1)+ch-48;return res*f;}
	template<typename tp>inline void read(tp &n){(Pin+40>=LEN)?flushin():void();tp res=0;char f=1,ch=' ';for(;ch<'0'||ch>'9';ch=Get())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=Get())res=(res<<3)+(res<<1)+ch-48;n=res*f;return;}
	inline int readstr(char *s){int len=0;char ch=Getc();while(!isalnum(ch))ch=Getc();while(isalnum(ch))s[len++]=ch,ch=Getc();return len;}
	#define Put(x) (PUF[Pout++]=x)
	char PUF[LEN];
	int Pout;
	inline void flushout(){fwrite(PUF,1,Pout,stdout),Pout=0;return;}
	inline void Putc(char x){if(Pout==LEN)flushout(),Pout=0;PUF[Pout++]=x;}
	template<typename tp>inline void write(tp a,char b='\n'){static int stk[40],top;(Pout+50>=LEN)?flushout():void();if(a<0)Put('-'),a=-a;else if(a==0)Put('0');for(top=0;a;a/=10)stk[++top]=a%10;for(;top;--top)Put(stk[top]^48);Put(b);return;}
	inline void wt_str(string s){for(char i:s)Putc(i);return;}
}
using namespace FAST_IO;

#define pii pair<int,int>
#define fi first
#define se second
#define ls (rt<<1)
#define rs (rt<<1|1)
#define Ls (tr[rt].lc)
#define Rs (tr[rt].rc)

const int N=2e5+10;
int n,f[N][2];
vector<int>e[N];
void dfs(int now,int fa)
{
	for(int to:e[now])
		if(to!=fa)dfs(to,now),f[now][0]+=f[to][0],f[now][1]+=f[to][0];
	int mx=-1e9;
	for(int to:e[now])
		if(to!=fa)mx=max(mx,f[to][1]-f[to][0]);
	f[now][0]+=mx;
	f[now][1]++;
	return;
}
int main()
{
	read(n);
	for(int i=1,u,v;i<n;i++)
	{
		read(u),read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	cout<<2*n-3*max(f[1][0],f[1][1]);
	flushout();
	return 0;
}




详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10140kb

input:

5
1 2
2 3
3 4
3 5

output:

-1294967292

result:

wrong answer 1st numbers differ - expected: '4', found: '-1294967292'