zoukankan      html  css  js  c++  java
  • Codeforces 504 A (Round #285 div.1 A) Misha and Forest

    Codeforces Round #285 (Div.1) A Misha and Forest

    水题水题水……

    题意:给你一些点,给出他们连通了多少个点以及这些点的下标的异或值,让你找出一个图

    题解:拓扑排序一发

    代码:

    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <queue>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    const int maxn = pow(2,16)+10;
    vector<pair<ll,ll> >ans;
    queue<ll> q;
    int d[maxn],v[maxn];
    bool u[maxn];
    int n;
    int main()
    {
    #ifndef ONLINE_JUDGE
        //freopen("F.in","r",stdin);
        //freopen("F.out","w",stdout);
    #endif
        cin >> n;
        for(ll i =0;i<n;i++)
        {
            cin >> d[i]>>v[i];
            if(d[i]<2)
            {
                q.push(i);
                u[i]=1;
            }
        }
        int t,tt,ttt;
        while(!q.empty())
        {
            t = q.front();
            q.pop();
            if(d[t]==0)
                continue;
            tt=v[t];
            v[tt] ^=t;
            d[t]--;
            d[tt]--;
            ans.push_back(make_pair(t,tt));
            if(d[tt]<2 && !u[tt])
            {
                q.push(tt);
                u[tt]=1;
            }
        }
        cout << ans.size() << endl;
        for(auto a:ans)
        {
            cout << a.first <<" " << a.second << endl;
        }
        return 0;
    }
    
    
  • 相关阅读:
    Ruby gem命令
    C语言中的static关键字
    Linux下clock计时函数学习
    open-falcon之dashboardportal说明.md
    open-falcon之graph
    open-falcon之query
    open-falcon之HBS
    open-falcon之judge
    open-falcon之transfer
    open-falcon之agent
  • 原文地址:https://www.cnblogs.com/Combustible-ice/p/5827905.html
Copyright © 2011-2022 走看看