54pts求助
  • 板块题目总版
  • 楼主A2_Zenith
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/19 09:41
  • 上次更新2023/11/3 02:45:45
查看原帖
54pts求助
906856
A2_Zenith楼主2023/8/19 09:41

题目:https://www.luogu.com.cn/problem/P3520

调两天了。

欢迎大家来hack以及列文虎克。

玄关。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<iomanip>
#include<map>
#define int long long
#define double long double
#define lc(p) p<<1
#define rc(p) p<<1|1
#define pii pair<int,int>
using namespace std;
struct edge{
    int v;
    int rev;
    bool exs;
};

int d[100007];
int del[100007];
bool vis[100007];
int reftop[100007];
vector<edge> e[100007];
stack<int> ans[100007];
int tpp=0;
void dfs(int now){
    vis[now]=true;
    for(int &i=del[now];i<e[now].size();){
        //cout<<now<<" "<<e[now][i].v<<" ";
        if(e[now][i].exs){
            //cout<<"yes"<<endl;
            edge t=e[now][i];
            //cout<<now<<" "<<i<<endl<<t.v<<" "<<t.rev<<endl;
            e[now][i].exs=0;
            e[t.v][t.rev].exs=0;
            dfs(t.v);
            i++;
        }
        else{
            i++;
            //cout<<"err"<<endl;
        }
    }
    ans[tpp].push(now);
}
int n,m;
signed main(){ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v,b1,b2;
        cin>>u>>v>>b1>>b2;
        if(b1!=b2){
            
            e[u].push_back({v,reftop[v]++,1});
            e[v].push_back({u,reftop[u]++,1});
            d[u]++;
            d[v]++;
        }
    }
    
    for(int i=1;i<=n;i++){
        if(d[i]&1){
            cout<<"NIE"<<endl;
            return 0;
        }
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            tpp++;
            dfs(i);
        }
    }
    cout<<tpp<<endl;
    for(int i=1;i<=tpp;i++){
        cout<<ans[i].size()-1<<" ";
        while(!ans[i].empty()){
            cout<<ans[i].top()<<" ";
            ans[i].pop();
        }
        cout<<endl;
    }
}







//9 15
//1 2 0 1
//2 3 0 1
//3 1 0 1
//4 5 0 1
//5 6 0 1
//6 4 0 1
//7 8 0 1
//8 9 0 1
//9 7 0 1
//3 6 0 1
//2 8 0 1
//5 7 0 1
//3 7 0 1
//2 5 0 1
//6 8 0 1

//5 10
//1 2 0 1
//1 3 0 1
//1 4 0 1
//1 5 0 1
//2 3 0 1
//2 4 0 1
//2 5 0 1
//3 4 0 1
//3 5 0 1
//4 5 0 1

//7 12
//1 2 0 1
//3 4 0 1
//5 6 0 1
//2 7 0 1
//6 7 0 1
//1 3 0 1
//3 5 0 1
//2 4 0 1
//4 6 0 1
//2 5 0 1
//4 5 0 1
//3 6 0 1


2023/8/19 09:41
加载中...