QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328658#1844. CactuskkioWA 3ms9836kbC++202.9kb2024-02-15 22:50:552024-02-15 22:50:56

Judging History

你现在查看的是最新测评结果

  • [2024-02-15 22:50:56]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9836kb
  • [2024-02-15 22:50:55]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
using namespace std;
#define fir first
#define sec second

#define lson(i) (tr[i].ls)
#define rson(i) (tr[i].rs)

#define FIO(file) freopen(file".in","r",stdin), freopen(file".out","w",stdout)

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef __int128_t i128;
typedef __uint128_t u128;
const int maxn=6e5+10;
int n,m;
vector<int> G[maxn];
bool del[maxn];
bool vis[maxn];
vector<int> R[maxn];
int ccnt,deg[maxn];
int dfn[maxn],low[maxn],times,ins[maxn],stk[maxn],top;
vector<int> opt; 
void delt(int u)
{
    del[u]=1;
    opt.push_back(u);
    for(int v:G[u])
        deg[v]--;
    for(int v:G[u])
        if(!del[v]&&deg[v]%2==1)delt(v);
}
void tarjan(int u,int fa)
{
    dfn[u]=low[u]=++times;
    stk[++top]=u;ins[u]=1;
    for(int v:G[u])
        if(v!=fa&&!del[v])
        {
            if(!dfn[v])
            {
                tarjan(v,u);
                low[u]=min(low[u],low[v]);
                if(low[v]>=dfn[u])
                {
                    ++ccnt;
                    int x=0;
                    while(x!=v)
                    {
                        x=stk[top];
                        ins[x]=0;top--;
                        R[x].push_back(ccnt);
                        R[ccnt].push_back(x);
                    }
                    R[u].push_back(ccnt);
                    R[ccnt].push_back(u);
                }
            }
            else if(ins[v])low[u]=min(low[u],dfn[v]);
        }
}

void dfs(int u,int fa)
{
    vis[u]=1;
    for(int v:R[u])
        if(!vis[v])
            dfs(v,u);
    if(u<=n&&!fa){opt.push_back(u);return;}
    if(u>n)
    {
        for(int i=0;i<R[u].size();i++)
            if(R[u][i]==fa){rotate(R[u].begin(),R[u].begin()+i,R[u].end());break;}
        //for(int v:R[u])cout<<v<<' ';cout<<'\n';
        for(int i=1,o=0;i<R[u].size();i++,o^=1)
            if(!o)opt.push_back(R[u][i]);
            else opt.push_back(R[u][i]+n);
        opt.push_back(R[u][1]+n);
        if(R[u].size()&1)opt.push_back(R[u].back());
        else opt.push_back(R[u].back()+n);
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        
        cin>>u>>v;
        deg[u]++;deg[v]++;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1;i<=n;i++)if(deg[i]%2==1)delt(i);
    ccnt=n;
    opt.push_back(0);
    for(int i=1;i<=n;i++)
        if(!dfn[i]&&!del[i])tarjan(i,0);
    for(int i=1;i<=n;i++)
        if(!del[i]&&!vis[i])dfs(i,0);
    cout<<0<<' '<<opt.size()<<'\n';
    for(int v:opt)
        if(v==0)cout<<2<<'\n';
        else cout<<1<<' '<<v<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9776kb

input:

3 3
1 2
1 3
2 3

output:

0 6
2
1 3
1 5
1 6
1 2
1 1

result:

ok You are right!

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 9836kb

input:

7 7
1 2
1 3
2 3
2 4
2 5
3 6
3 7

output:

0 8
1 4
1 2
1 1
1 6
1 3
2
1 5
1 7

result:

wrong answer The number of remaining edges is not equal to m'.