QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611950 | #1000. 边三连通分量 | Lehe | TL | 30ms | 181216kb | C++14 | 3.2kb | 2024-10-05 00:36:34 | 2024-10-05 00:36:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define i128 __int128
#define pii pair<int,int>
#define fir first
#define sec second
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define pb push_back
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
int n,m,dfn[3000010],low[3000010],dfc,fa[3000010],val[3000010],cnt,pm;
bool b[3000010],vis[3000010],b2[3000010];
int ui[3000010],vi[3000010];
ull w[3000010];
unordered_map<ull,int>mp,ed;
mt19937_64 rnd(time(0));
inline int randint(){return rnd();}//|1ull*rnd()<<64;}
vector<pii>g[3000010];
vector<int>ans[3000010];
void tarjan(int u,int f)
{
dfn[u]=low[u]=++dfc;
for(auto x:g[u])
{
int v=x.fir,id=x.sec;
if(!dfn[v])
{
tarjan(v,/*u*/id);
chmin(low[u],low[v]);
// if(low[v]>dfn[u])b[id]=b[id^1]=1;
if(low[v]>=dfn[v])b[id]=b[id^1]=1;
}
else if(/*v!=f*/id!=(f^1))chmin(low[u],dfn[v]);
}
}
void dfs3(int u,int f)
{
// cout<<" dfs3: "<<u<<endl;
ans[cnt].pb(u);
for(auto x:g[u])
{
int v=x.fir;
int id=x.sec;
// cout<<"!!!!!!!!!!!!"<<u<<" "<<v<<endl;
// if(!b[v]&&!b2[v]&&vis[v]&&v!=f)
if(!b[id]&&!b2[id]&&vis[id]&&v!=f)
dfs3(v,f);
}
}
void dfs2(int u,int eid)
{
// cout<<" dfs2:"<<u<<endl;
for(auto x:g[u])
{
int v=x.fir,id=x.sec;
if(!b[id]&&!b2[id]&&vis[id])dfs2(v,id);
}
if(mp[w[u]])
// if(mp[w[u]]!=mp.find)
{
int v=mp[w[u]];
// cout<<"difnew: "<<u<<" "<<v<<endl;
cnt++;
dfs3(u,v);
vis[eid]=0;
int f=fa[u];
g[f].pb({v,++pm});
vis[pm]=1;
fa[v]=f;
mp[w[u]]=v;
}
else mp[w[u]]=u;
}
void dfs(int u,int fr,int eid)
{
dfn[u]=++dfc;
// cout<<"dfn["<<u<<"]="<<dfn[u]<<endl;
for(auto x:g[u])
{
int v=x.fir,id=x.sec;
// if(!b[v]&&v!=f)
// if(!b[id]&&v!=f)
if(!b[id]&&id!=(eid^1))
{
if(dfn[v])
{
if(dfn[v]>dfn[u])continue;
// val[id]=randint();
ull vi=randint();
// cout<<"!!val="<<val[id]<<endl;
w[u]^=vi;
w[v]^=vi;
ed[vi]=1;
}
else
{
// cout<<" dvdv "<<u<<" "<<v<<endl;
vis[id]=1;
fa[v]=u;
dfs(v,id/*,u*/,id);
w[u]^=w[v];
}
}
}
// cout<<"!!! dfs1:"<<u<<endl;
if(ed[w[u]])b2[eid]=b2[eid^1]=1;//,cout<<"dsfavfb"<<eid<<endl;
if(b2[eid]||!eid)
{
// cout<<" !!!"<<u<<" "<<eid<<endl;
mp.clear();
dfs2(u,0);
// vis[eid]=0;
cnt++;
dfs3(u,0);
}
}
bool cmp(vector<int>a,vector<int>b)
{
return a[0]<b[0];
}
signed main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
// int u,v;
cin>>ui[i]>>vi[i];
ui[i]++,vi[i]++;
// cout<<"gfhnsb "<<i<<" "<<ui[i]<<" "<<vi[i]<<endl;
// g[u].pb(v);
g[ui[i]].pb({vi[i],2*i});
g[vi[i]].pb({ui[i],2*i+1});
// val[i]=randint();
}
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i,0);
// cout<<"tarjan:end"<<endl;
// for(int i=1;i<=m;i++)cout<<b[i];
// cout<<endl;
memset(dfn,0,sizeof(dfn));
dfc=0;
pm=2*m+1;
for(int i=1;i<=n;i++)
if(!dfn[i])
dfs(i,0,0);
for(int i=1;i<=cnt;i++)sort(ans[i].begin(),ans[i].end());
sort(ans+1,ans+cnt+1/*,cmp*/);
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++)
{
cout<<ans[i].size()<<" ";
for(auto x:ans[i])cout<<x-1<<" ";
cout<<endl;
}
return 0;
}
/*
5 7
1 2
1 3
1 4
2 3
2 4
3 4
5 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 30ms
memory: 181192kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
3 2 0 2 1 1 1 3
result:
ok OK
Test #2:
score: 0
Accepted
time: 21ms
memory: 181216kb
input:
13 21 4 5 8 7 12 3 3 10 1 5 10 2 0 0 11 4 2 12 9 1 9 0 7 8 7 6 9 1 8 2 12 10 11 0 8 6 3 2 5 9 4 11
output:
6 1 0 3 1 5 9 4 2 3 10 12 2 4 11 1 6 2 7 8
result:
ok OK
Test #3:
score: -100
Time Limit Exceeded
input:
200000 200000 127668 148778 77100 11865 85144 199231 39485 84917 102044 187263 130204 174776 26220 198288 162188 12078 92196 146334 120537 38083 150353 160479 18707 6545 101149 25450 62271 9177 38892 6454 11709 191939 89247 145109 140599 121858 197410 148980 55975 169098 128576 59852 68224 182347 89...