Submission #68575629
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> ppl;
typedef pair<ll,ppl> pppl;
typedef pair<ll,pppl> pppppl;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) begin(a),end(a)
#define sz(a) (int)(a).size()
#define F first
#define S second
#define bs(A,x) binary_search(all(A),x)
#define lb(A,x) (ll)(lower_bound(all(A),x)-A.begin())
#define ub(A,x) (ll)(upper_bound(all(A),x)-A.begin())
#define cou(A,x) (ll)(upper_bound(all(A),x)-lower_bound(all(A),x))
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
//*
using mint=modint998244353;
const ll mod=998244353;
//*/
/*
using mint=modint1000000007;
const ll mod=1000000007;
//*/
//using mint=modint;
//*
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;
typedef vector<vvvm> vvvvm;
ostream&operator<<(ostream&os,mint a){os<<a.val();return os;}
istream&operator>>(istream&is,mint&a){int x;is>>x;a=mint(x);return is;}
//*/
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>v){rep(i,0,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll N,M;cin>>N>>M;
vvl E(N);
dsu G(N);
vector<pl>es;
rep(i,0,M){
ll u,v;cin>>u>>v;u--;v--;
if(G.same(u,v)){
es.emplace_back(pl(u,v));
}
else{
E[u].emplace_back(v);
E[v].emplace_back(u);
G.merge(u,v);
}
}
vl P(N),D(N),tour,idx(N),out(N);
function<void(ll)>dfs=[&](ll v){
tour.emplace_back(v);
idx[v]=sz(tour)-1;
for(auto u:E[v])if(u!=P[v]){
P[u]=v;
D[u]=D[v]+1;
dfs(u);
}
out[v]=sz(tour);
};
dfs(0);
vvl dou(20,vl(N));
dou[0]=P;
rep(i,1,20)rep(j,0,N)dou[i][j]=dou[i-1][dou[i-1][j]];
auto up=[&](ll v,ll d){
rep(i,0,20)if((d>>i)%2)v=dou[i][v];
return v;
};
auto lca=[&](ll u,ll v){
if(D[u]>D[v])swap(u,v);
v=up(v,D[v]-D[u]);
rrep(i,0,20)if(dou[i][u]!=dou[i][v])u=dou[i][u],v=dou[i][v];
if(u==v)return u;
return P[u];
};
ll L=sz(es);
vl V(2*L);
rep(i,0,L)V[2*i]=es[i].F,V[2*i+1]=es[i].S;
V.emplace_back(0);
V.emplace_back(N-1);
vvl LCA(2*L+2,vl(2*L+2));
rep(i,0,2*L+2)rep(j,0,2*L+2)LCA[i][j]=lca(V[i],V[j]);
vl ans(N),rev(N);
fenwick_tree<ll>F(N);
vl nec(2*L+2);
rep(i,0,1<<L){
vl X={2*L,2*L+1};
rep(j,0,L)if((i>>j)%2)X.emplace_back(2*j),X.emplace_back(2*j+1);
sort(all(X),[&](ll u,ll v){return idx[V[u]]<idx[V[v]];});
for(auto x:X)F.add(idx[V[x]],1);
stack<ll>st;
ll l=sz(X)/2-1;
rep(i,0,sz(X)){
st.emplace(X[i]);
while(sz(st)>1){
ll v=st.top();st.pop();
ll u=st.top();
ll t=LCA[u][v];
if(F.sum(idx[t],out[t])==2){
l+=D[V[u]]+D[V[v]]-2*D[t];
F.add(idx[V[u]],-1);
F.add(idx[V[v]],-1);
nec[u]=v;
nec[v]=u;
st.pop();
}
else{
st.emplace(v);
break;
}
}
}
if(!sz(st)){
ll v=2*L,cnt=0;
do{
v=nec[v];
cnt++;
v^=1;
}while(v!=2*L);
if(cnt==sz(X)/2)ans[l]++;
}
while(sz(st)){
ll v=st.top();st.pop();
F.add(idx[V[v]],-1);
}
}
ans.erase(ans.begin());
cout<<ans<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Count Simple Paths 2 |
User |
TKTYI |
Language |
C++ 20 (gcc 12.2) |
Score |
600 |
Code Size |
4244 Byte |
Status |
AC |
Exec Time |
3833 ms |
Memory |
79136 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
|
|
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 |
1 ms |
3624 KiB |
00_sample_01.txt |
AC |
2 ms |
3508 KiB |
00_sample_02.txt |
AC |
3 ms |
3540 KiB |
01_test_00.txt |
AC |
3249 ms |
39520 KiB |
01_test_01.txt |
AC |
3401 ms |
65096 KiB |
01_test_02.txt |
AC |
254 ms |
41336 KiB |
01_test_03.txt |
AC |
3534 ms |
64300 KiB |
01_test_04.txt |
AC |
95 ms |
52392 KiB |
01_test_05.txt |
AC |
3384 ms |
63764 KiB |
01_test_06.txt |
AC |
43 ms |
26036 KiB |
01_test_07.txt |
AC |
3540 ms |
63492 KiB |
01_test_08.txt |
AC |
25 ms |
20968 KiB |
01_test_09.txt |
AC |
3585 ms |
65004 KiB |
01_test_10.txt |
AC |
28 ms |
23488 KiB |
01_test_11.txt |
AC |
3408 ms |
64092 KiB |
01_test_12.txt |
AC |
3450 ms |
67624 KiB |
01_test_13.txt |
AC |
3348 ms |
72436 KiB |
01_test_14.txt |
AC |
3833 ms |
63496 KiB |
01_test_15.txt |
AC |
3740 ms |
68320 KiB |
01_test_16.txt |
AC |
2839 ms |
77192 KiB |
01_test_17.txt |
AC |
3200 ms |
77148 KiB |
01_test_18.txt |
AC |
3150 ms |
77036 KiB |
01_test_19.txt |
AC |
2923 ms |
76996 KiB |
01_test_20.txt |
AC |
3060 ms |
77128 KiB |
01_test_21.txt |
AC |
3379 ms |
77192 KiB |
01_test_22.txt |
AC |
3410 ms |
72992 KiB |
01_test_23.txt |
AC |
3518 ms |
74600 KiB |
01_test_24.txt |
AC |
3510 ms |
71160 KiB |
01_test_25.txt |
AC |
3607 ms |
72808 KiB |
01_test_26.txt |
AC |
3007 ms |
77168 KiB |
01_test_27.txt |
AC |
3173 ms |
77120 KiB |
01_test_28.txt |
AC |
3062 ms |
78972 KiB |
01_test_29.txt |
AC |
2737 ms |
79136 KiB |
01_test_30.txt |
AC |
287 ms |
66620 KiB |
01_test_31.txt |
AC |
294 ms |
71520 KiB |
01_test_32.txt |
AC |
2705 ms |
69532 KiB |
01_test_33.txt |
AC |
2579 ms |
74608 KiB |
01_test_34.txt |
AC |
2814 ms |
73660 KiB |
01_test_35.txt |
AC |
3431 ms |
61500 KiB |
01_test_36.txt |
AC |
3438 ms |
61436 KiB |
01_test_37.txt |
AC |
3539 ms |
61464 KiB |
01_test_38.txt |
AC |
3428 ms |
61440 KiB |
01_test_39.txt |
AC |
3248 ms |
61464 KiB |
01_test_40.txt |
AC |
3564 ms |
61448 KiB |
01_test_41.txt |
AC |
3475 ms |
62584 KiB |
01_test_42.txt |
AC |
3688 ms |
62644 KiB |
01_test_43.txt |
AC |
2614 ms |
61892 KiB |
01_test_44.txt |
AC |
2718 ms |
61824 KiB |
01_test_45.txt |
AC |
1705 ms |
3640 KiB |
01_test_46.txt |
AC |
3252 ms |
65004 KiB |
01_test_47.txt |
AC |
1 ms |
3544 KiB |
01_test_48.txt |
AC |
131 ms |
73508 KiB |
01_test_49.txt |
AC |
109 ms |
72496 KiB |
01_test_50.txt |
AC |
3529 ms |
64856 KiB |
01_test_51.txt |
AC |
3555 ms |
64200 KiB |
01_test_52.txt |
AC |
3672 ms |
66820 KiB |
01_test_53.txt |
AC |
108 ms |
75232 KiB |
01_test_54.txt |
AC |
118 ms |
68816 KiB |