Submission #16016662


Source Code Expand

#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
using namespace std;

struct IO
{
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
  	char buf[MAXSIZE],*p1,*p2;
  	char pbuf[MAXSIZE],*pp;
  	IO():p1(buf),p2(buf),pp(pbuf){}
  	inline char gc() {
    	return getchar();
    	if (p1==p2) p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
    	return p1==p2?' ':*p1++;
  	}
	inline bool blank(char ch) {return ch==' '||ch =='\n'||ch == '\r'||ch == '\t';}
  	template <class T>
  	inline void read(T &x)
	{
	    register double tmp=1;register bool sign=0; x=0;
	    register char ch=gc();
	    for (;!isdigit(ch);ch=gc()) if(ch=='-') sign=1;
	    for (;isdigit(ch);ch=gc()) x=x*10+(ch-'0');
	    if (ch=='.') for (ch=gc();isdigit(ch);ch=gc()) tmp/=10.0,x+=tmp*(ch-'0');
	    if (sign) x=-x;
  	}
  	inline void read(char *s)
	{
    	register char ch=gc();
		for (;blank(ch);ch=gc());
		for (;!blank(ch);ch=gc()) *s++=ch;
    	*s=0;
  	}
  	inline void read(char &c) {for(c=gc();blank(c);c=gc());}
  	template<class t> inline void write(t x){
		if(x<0) putchar('-'),write(-x);
		else{if(x>9) write(x/10);putchar('0'+x%10);}
	}
} io;

#define int long long 

const int N=1e5+5;
const int mo=998244353;

int n,m,dep[N],l[N],head[N],cnt;
vector<int> f[N];

struct Node
{
	int nex,to;
};
Node e[N<<2];

inline void jia(int u,int v)
{
	e[++cnt].nex=head[u];
	head[u]=cnt;
	e[cnt].to=v;
}

inline void dfs(int u,int fa,int d)
{
	dep[u]=d;
	l[u]=max(d-1,0ll);
	GO(i,u) if(e[i].to^fa) dfs(e[i].to,u,d+1);
}

inline void dp(int u,int fa)
{
	f[u].clear();
	GO(i,u) if(e[i].to^fa) dp(e[i].to,u);
	For(i,0,l[u])
	{
		int gs=1ll;
		GO(j,u)
		{
			int v=e[j].to;
			if(v^fa)
			{
				if(l[v]>i) gs=(gs*(f[v][i+1]+f[v][0]))%mo;
				else gs=(gs*f[v][0])%mo;
			}
		}
		f[u].pb(gs);
	}
}

signed main()
{
//	freopen("destiny.in","r",stdin);
//	freopen("destiny.out","w",stdout);

	mem(head,0);
	io.read(n);
	For(i,1,n-1)
	{
		int x,y;
		io.read(x),io.read(y);
		jia(x,y);
		jia(y,x);
	}
	dfs(1,0,1);
	io.read(m);
	For(i,1,m)
	{
		int x,y;
		io.read(x),io.read(y);
		l[y]=min(l[y],dep[y]-dep[x]-1);
	}
	dp(1,0);
	io.write(f[1][0]);
	return 0;
}

Submission Info

Submission Time
Task F - Tree and Constraints
User mztkn
Language C++ (GCC 9.2.1)
Score 0
Code Size 2571 Byte
Status RE
Exec Time 117 ms
Memory 6720 KiB

Compile Error

./Main.cpp: In member function ‘void IO::read(T&)’:
./Main.cpp:29:22: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |      register double tmp=1;register bool sign=0; x=0;
      |                      ^~~
./Main.cpp:29:42: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |      register double tmp=1;register bool sign=0; x=0;
      |                                          ^~~~
./Main.cpp:30:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   30 |      register char ch=gc();
      |                    ^~
./Main.cpp: In member function ‘void IO::read(char*)’:
./Main.cpp:38:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   38 |      register char ch=gc();
      |                    ^~
./Main.cpp: In instantiation of ‘void IO::read(T&) [with T = long long int]’:
./Main.cpp:104:11:   required from here
./Main.cpp:29:22: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |      register double tmp=1;register bool sign=0; x=0;
      |                      ^~~
./Main.cpp:29:42: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |      register double tmp=1;register bool sign=0; x=0;
      |                                          ^~~~
./Main.cpp:30:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   30 |      register char ch=gc();
      |                    ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
RE × 1
AC × 3
WA × 5
RE × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All dense_01.txt, dense_02.txt, dense_03.txt, dense_04.txt, dense_05.txt, large_ans.txt, line_01.txt, line_02.txt, line_03.txt, no_overlap.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, star_01.txt, star_02.txt, star_03.txt
Case Name Status Exec Time Memory
dense_01.txt RE 112 ms 6372 KiB
dense_02.txt RE 108 ms 6224 KiB
dense_03.txt RE 111 ms 6312 KiB
dense_04.txt RE 110 ms 6340 KiB
dense_05.txt RE 107 ms 6356 KiB
large_ans.txt WA 7 ms 6592 KiB
line_01.txt WA 6 ms 6596 KiB
line_02.txt WA 8 ms 6592 KiB
line_03.txt WA 10 ms 6688 KiB
no_overlap.txt WA 10 ms 6708 KiB
random_01.txt RE 117 ms 6320 KiB
random_02.txt RE 108 ms 6320 KiB
random_03.txt RE 108 ms 6348 KiB
random_04.txt RE 110 ms 6232 KiB
random_05.txt RE 108 ms 6428 KiB
random_06.txt RE 108 ms 6376 KiB
random_07.txt RE 107 ms 6268 KiB
random_08.txt RE 109 ms 6388 KiB
random_09.txt RE 108 ms 6316 KiB
random_10.txt RE 108 ms 6384 KiB
sample_01.txt AC 6 ms 6520 KiB
sample_02.txt AC 6 ms 6720 KiB
sample_03.txt AC 5 ms 6600 KiB
sample_04.txt RE 112 ms 6364 KiB
star_01.txt RE 110 ms 6388 KiB
star_02.txt RE 110 ms 6392 KiB
star_03.txt RE 108 ms 6316 KiB