QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327818 | #1844. Cactus | HBYoutze | RE | 9ms | 38600kb | C++14 | 3.0kb | 2024-02-15 14:48:47 | 2024-02-15 14:48:48 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
//#define mod 1000000007
using namespace std;
int n,m,head[300010],cnt=1,ru[300010],tmp,cz[600010],tot;
int huan[300010],ruh[300010],head2[300010],cnt2,tmp2,zhan[300010],ztop;
bool vis[300010],vis2[300010],vis3[300010],vis4[1000010];
vector<int> h[300010],d[300010];
set<int> hu[300010];
struct edge
{
int next,to;
}a[1000010],a2[1000010];
void ad(int u,int v)
{
a[++cnt].to=v;a[cnt].next=head[u];head[u]=cnt;ru[v]++;
a[++cnt].to=u;a[cnt].next=head[v];head[v]=cnt;ru[u]++;
}
void ad2(int u,int v)
{
a2[++cnt2].to=v;a2[cnt2].next=head2[u];head2[u]=cnt2;ruh[v]++;
a2[++cnt2].to=u;a2[cnt2].next=head2[v];head2[v]=cnt2;ruh[u]++;
}
void dfs(int x,int fa)
{
if(vis2[x])
{
int now=ztop;tmp2++;
h[tmp2].push_back(x);huan[tmp2]++;
for(auto j:d[x]) ad(tmp2,j);
d[x].push_back(tmp2);
while(zhan[now]!=x)
{
h[tmp2].push_back(zhan[now]);
for(auto j:d[zhan[now]]) ad(tmp2,j);
if(!d[zhan[now]].empty()) hu[tmp2].insert(zhan[now]);
d[zhan[now]].push_back(tmp2);
now--;huan[tmp2]++;
}
return;
}
vis2[x]=1;zhan[++ztop]=x;
for(int i=head[x];i;i=a[i].next)
{
int v=a[i].to;
if(vis[v]||v==fa||vis4[i]||vis4[i^1]) continue;
dfs(v,x);vis4[i]=1;ztop--;
}
}
signed main()
{
cin>>n>>m;tmp=n;
for(int i=1;i<=m;i++)
{
int u,v;cin>>u>>v;ad(u,v);
}
set<int> echo;cout<<"0 ";
for(int i=1;i<=n;i++)
{
if(ru[i]%2) echo.insert(i);
}
while(!echo.empty())
{
set<int>::iterator it=echo.begin();
int now=*it;echo.erase(now);
cz[++tot]=now;vis[now]=1;tmp--;
for(int i=head[now];i;i=a[i].next)
{
int v=a[i].to;
if(vis[v]) continue;
ru[v]--;
if(ru[v]%2) echo.insert(v);
else echo.erase(v);
if(!ru[v]) tmp--;
}
}
queue<int> q;
if(tmp==0) goto Marshall_Maximizer;
cz[++tot]=0;
for(int i=1;i<=n;i++)
{
if(!vis[i]&&!vis2[i]) dfs(i,0);
}
for(int i=1;i<=tmp2;i++)
{
if(ruh[i]==1||!ruh[i]) q.push(i);
}
while(!q.empty())
{
int u=q.front();q.pop();
int k,fl=0,fl2=0;
if(ruh[u]) k=*hu[u].begin();
else k=h[u][0];
for(auto j:h[u])
{
if(j==k)
{
fl2=fl;continue;
}
cz[++tot]=j+fl*n;
fl^=1;
}
int lst,nxt;
for(int i=0;i<h[u].size();i++)
{
if(h[u][i]!=k) continue;
if(i==0) lst=h[u][h[u].size()-1];
else lst=h[u][i-1];
if(i==h[u].size()-1) nxt=h[u][0];
else nxt=h[u][i+1];
break;
}
if(huan[u]%2)
{
if(fl2)
{
cz[++tot]=lst+n;cz[++tot]=nxt;
}
else
{
cz[++tot]=lst;cz[++tot]=nxt+n;
}
}
else
{
if(fl2)
{
cz[++tot]=lst+n;cz[++tot]=nxt+n;
}
else
{
cz[++tot]=lst;cz[++tot]=nxt;
}
}
vis3[u]=1;
if(!ruh[u]) cz[++tot]=k;
for(int i=head2[u];i;i=a2[i].next)
{
int v=a2[i].to;
if(vis3[v]) continue;
ru[v]--;
if(ru[v]==1) q.push(v);
if(ru[v]) hu[v].erase(k);
}
}
Marshall_Maximizer:
cout<<tot<<'\n';
for(int i=1;i<=tot;i++)
{
if(cz[i]==0) cout<<"2\n";
else cout<<"1 "<<cz[i]<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 38428kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 2 1 6 1 3 1 5 1 1
result:
ok You are right!
Test #2:
score: 0
Accepted
time: 0ms
memory: 38600kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 5 1 4 1 2 1 1 1 6 1 3
result:
ok You are right!
Test #3:
score: -100
Runtime Error
input:
300000 368742 1 143504 1 234282 2 91276 2 296320 3 274816 4 212293 4 258214 5 253489 5 295826 6 96521 6 252745 6 267103 6 269879 7 5293 7 295586 8 44304 8 57067 8 233291 9 190526 10 18682 11 7440 12 24695 12 172561 12 243692 12 280316 13 80152 13 268749 14 146394 14 207280 15 151280 15 226848 16 458...