codeforces 1217d D. Coloring Edges

Meaning of the questions: not only have a one color to the edges of the graph, stained ring. You need to ask several colors and coloring scheme.

Up to 2 colors. One kind of acyclic, when two kinds of rings. Dfs sentence rings with similar tarjan, still stack point there has to be access ring. backedge dye 2, other dye 1. simplify it. If a cycloalkyl ai <bi edges dye 1, ai> bi dye 2 side. Correctness seems to be correct.

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#include <unordered_set>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
typedef long long lon;
typedef pair<lon,lon> pii ;
const lon SZ=100010,SSZ=0,APB=26,INF=0x7FFFFFF,mod=1000000007;
lon n,m;
vector<int> mp[SZ];
pii in[SZ];
bool vst[SZ],ok,inq[SZ];

void dfs(int x,int p)
{
    vst[x]=1;
    inq[x]=1;
    for(int i=0;i<mp[x].size();++i)
    {
        int to=mp[x][i];
        //if(to!=p)
        //{
            if(inq[to])ok=1;
            else if(!vst[to])dfs(to,x);
        //}
    }
    inq[x]=0;
}
 
void init()
{
    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        int u,v;
        cin>>u>>v;
        mp[u].push_back(v);
        in[i]=mkp(u,v);
    }
    for(int i=1;i<=n;++i)
    if(!vst[i])dfs(i,-1);
    if(ok)
    {
        cout<<2<<endl;
        for(int i=1;i<=m;++i)
        {
            if(i!=1)cout<<" ";
            cout<<(in[i].first<in[i].second?1:2);
        }
        cout<<endl;
    }
    else
    {
        cout<<1<<endl;
        for(int i=1;i<=m;++i)
        {
            if(i!=1)cout<<" ";
            cout<<1;
        }
        cout<<endl;
    }
}
 
void work()
{
    
}
 
int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    //lon casenum;
    //cin>>casenum;
    //for(lon tim=1;tim<=casenum;++tim)
    {
        init();
        work();
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/gaudar/p/11521470.html