Submission #68552307


Source Code Expand

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
namespace IO{
	const int sz=1<<22;
	char a[sz+5],b[sz+5],*p1=a,*p2=a,*t=b,p[205];
	#define gc() (p1==p2?(p2=(p1=a)+fread(a,1,sz,stdin),p1==p2?EOF:*p1++):*p1++)
	#define flush() (fwrite(b,1,t-b,stdout),t=b)
	#define pc(x) (*t++=x,(t-b==sz)?flush():nullptr)
	template<class T> inline void read(T &x){
		x=0; char c=gc(),fushu=0;
		while(!isdigit(c)){if(c=='-')fushu=1; c=gc();}
		while(isdigit(c))x=x*10+(c^48),c=gc();
		if(fushu) x=-x;
	}
	inline void read(char &x){
		x=gc();
		while(!isgraph(x))x=gc();
	}
	inline void read(char *x){
		char c=gc();
		while(!isgraph(c))c=gc();
		while(isgraph(c))*x++=c,c=gc();
		*x='\0';
	}
	inline void read(string &x){
		x=""; char c=gc();
		while(!isgraph(c))c=gc();
		while(isgraph(c))x.push_back(c),c=gc();
	}
	template <typename T,typename ...Args> inline void read(T &x,Args &...args) { read(x),read(args...); }
	template<class T> inline void write(T x){
		if(x<0)pc('-'),x=-x;
		if(!x)pc('0');
		int l=0;
		while(x)p[++l]=(x%10)^48,x/=10;
		while(l)pc(p[l--]);
	}
	inline void write(char &x){pc(x);}
	inline void write(const char &x){pc(x);}
	inline void write(char *x){while(*x!='\0')pc(*x++);}
	inline void write(const char *x){while(*x!='\0')pc(*x++);}
	inline void write(string &x){for(auto c:x)pc(c);}
	template <typename T,typename ...Args> inline void write(T x,Args ...args) { write(x),write(args...); }
	struct F{~F(){flush();}}f;
	#undef gc
	#undef flush
	#undef pc
};
using IO::read;
using IO::write;
#define IOS ios::sync_with_stdio(0); cin.tie(0)
#define frein(name) freopen(name".in","r",stdin)
#define freout(name) freopen(name".out","w",stdout)
#define usefile(name) frein(name),freout(name)
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define fd(i,r,l) for(int i=(r);i>=(l);--i)
#define ll long long
#define ull unsigned long long
#define ld long double
#define it128 __int128
#define pi pair<int,int>
#define pl pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vp vector<pi>
#define Size(x) ((int)x.size())
const int N=2e5+5;
int n,m;
vi g[N];
vp e[N];
int vis[N],dep[N],fa[N][18],dfn[N],dn;
void dfs(int x,int y) {
	dfn[x]=++dn;
	dep[x]=dep[y]+1,vis[x]=1,fa[x][0]=y;
	fo(i,1,17) fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int v:g[x]) if(!vis[v]) dfs(v,x);
}
int lca(int x,int y) {
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=dep[x]-dep[y],j=0;i;i>>=1,++j) if(i&1) x=fa[x][j];
	if(x==y) return x;
	fd(i,17,0) if(fa[x][i]!=fa[y][i]) 
		x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int getdis(int x,int y) {
	int z=lca(x,y);
	return dep[x]+dep[y]-2*dep[z];
}
int d[N],tot;
int ans[N],bz[N];
void solve(int x,int d) {
	if(x==n) {ans[d]++; return;}
	bz[x]=1;
	for(auto [v,dis]:e[x]) {
		if(!bz[v]) solve(v,d+dis);
	}
	bz[x]=0;
}
signed main(){
	read(n,m);
	fo(i,1,m) {
		int u,v; read(u,v);
		g[u].pb(v),g[v].pb(u);
	}
	dfs(1,0);
	fo(i,1,n) for(int v:g[i]) if(fa[i][0]!=v&&fa[v][0]!=i&&v>i) d[++tot]=i,d[++tot]=v;
	d[++tot]=n,d[++tot]=1;
	sort(d+1,d+1+tot,[](int x,int y) {return dfn[x]<dfn[y];});
	tot=unique(d+1,d+1+tot)-d-1;
	int tmp=tot;
	fo(i,1,tmp-1) d[++tot]=lca(d[i],d[i+1]);
	sort(d+1,d+1+tot,[](int x,int y) {return dfn[x]<dfn[y];});
	tot=unique(d+1,d+1+tot)-d-1;
	fo(i,1,tot-1) {
		int u=lca(d[i],d[i+1]),v=d[i+1];
		int dis=getdis(u,v);
		e[u].pb({v,dis}),e[v].pb({u,dis});
	}
	fo(i,1,n) for(int v:g[i]) if(fa[i][0]!=v&&fa[v][0]!=i&&v>i) {
		e[i].pb({v,1}),e[v].pb({i,1});
	}
	solve(1,0);
	fo(i,1,n-1) write(ans[i],' ');
	return 0;
}

Submission Info

Submission Time
Task G - Count Simple Paths 2
User dengchengyu
Language C++ 20 (gcc 12.2)
Score 600
Code Size 3689 Byte
Status AC
Exec Time 620 ms
Memory 43392 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 58
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt, 01_test_46.txt, 01_test_47.txt, 01_test_48.txt, 01_test_49.txt, 01_test_50.txt, 01_test_51.txt, 01_test_52.txt, 01_test_53.txt, 01_test_54.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 3532 KiB
00_sample_01.txt AC 3 ms 3656 KiB
00_sample_02.txt AC 3 ms 3652 KiB
01_test_00.txt AC 44 ms 23680 KiB
01_test_01.txt AC 76 ms 37604 KiB
01_test_02.txt AC 43 ms 24336 KiB
01_test_03.txt AC 77 ms 37128 KiB
01_test_04.txt AC 59 ms 30568 KiB
01_test_05.txt AC 76 ms 36564 KiB
01_test_06.txt AC 25 ms 16496 KiB
01_test_07.txt AC 79 ms 37136 KiB
01_test_08.txt AC 19 ms 13396 KiB
01_test_09.txt AC 89 ms 37996 KiB
01_test_10.txt AC 20 ms 14584 KiB
01_test_11.txt AC 78 ms 37652 KiB
01_test_12.txt AC 304 ms 39128 KiB
01_test_13.txt AC 620 ms 40076 KiB
01_test_14.txt AC 433 ms 40220 KiB
01_test_15.txt AC 601 ms 40476 KiB
01_test_16.txt AC 202 ms 42536 KiB
01_test_17.txt AC 174 ms 42552 KiB
01_test_18.txt AC 78 ms 42432 KiB
01_test_19.txt AC 85 ms 42544 KiB
01_test_20.txt AC 89 ms 42500 KiB
01_test_21.txt AC 106 ms 42588 KiB
01_test_22.txt AC 124 ms 41016 KiB
01_test_23.txt AC 118 ms 42012 KiB
01_test_24.txt AC 117 ms 42196 KiB
01_test_25.txt AC 118 ms 41928 KiB
01_test_26.txt AC 121 ms 42704 KiB
01_test_27.txt AC 121 ms 42640 KiB
01_test_28.txt AC 101 ms 43392 KiB
01_test_29.txt AC 95 ms 43384 KiB
01_test_30.txt AC 76 ms 40332 KiB
01_test_31.txt AC 85 ms 42352 KiB
01_test_32.txt AC 88 ms 38588 KiB
01_test_33.txt AC 79 ms 43328 KiB
01_test_34.txt AC 85 ms 41308 KiB
01_test_35.txt AC 72 ms 34348 KiB
01_test_36.txt AC 131 ms 34488 KiB
01_test_37.txt AC 85 ms 34340 KiB
01_test_38.txt AC 118 ms 34396 KiB
01_test_39.txt AC 92 ms 34312 KiB
01_test_40.txt AC 84 ms 34316 KiB
01_test_41.txt AC 283 ms 34328 KiB
01_test_42.txt AC 344 ms 34284 KiB
01_test_43.txt AC 46 ms 33656 KiB
01_test_44.txt AC 48 ms 34276 KiB
01_test_45.txt AC 3 ms 3496 KiB
01_test_46.txt AC 75 ms 36680 KiB
01_test_47.txt AC 3 ms 3572 KiB
01_test_48.txt AC 81 ms 43052 KiB
01_test_49.txt AC 77 ms 43168 KiB
01_test_50.txt AC 83 ms 37968 KiB
01_test_51.txt AC 119 ms 39748 KiB
01_test_52.txt AC 243 ms 40096 KiB
01_test_53.txt AC 59 ms 43256 KiB
01_test_54.txt AC 60 ms 38444 KiB