QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328660#1844. CactuskkioWA 265ms37112kbC++203.0kb2024-02-15 22:54:472024-02-15 22:54:48

Judging History

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

  • [2024-02-15 22:54:48]
  • 评测
  • 测评结果:WA
  • 用时:265ms
  • 内存:37112kb
  • [2024-02-15 22:54:47]
  • 提交

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()>2)
        {
            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(!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';
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3720kb

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: 0
Accepted
time: 2ms
memory: 3608kb

input:

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

output:

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

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 265ms
memory: 37112kb

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...

output:

0 570434
1 3
1 274816
1 273658
1 217572
1 248509
1 231418
1 73094
1 117739
1 11855
1 48428
1 55953
1 121689
1 234392
1 181317
1 238712
1 77369
1 105062
1 6838
1 130659
1 8
1 44304
1 9
1 10
1 18682
1 63155
1 148043
1 194189
1 26612
1 1155
1 31020
1 108936
1 71065
1 77412
1 124995
1 126920
1 53663
1 4...

result:

wrong answer The deg of 481 is not odd.