zoukankan      html  css  js  c++  java
  • codeforce1005F

    题解:咕咕

    字符串没学过各种错?还有vector越界。。。。

    考试的时候这样就完了。。。。

    最究极原因还是懒。。。无法快速换策略。

    希望明天模拟赛能改进吧。。。

    #include<bits/stdc++.h>
    using namespace std;
    const long long M=3e6;
    #define ll long long
    struct re{
        ll v;
        ll nex;
    };
    re edge[M];
    ll d[M],n,m,k,tot=0,cnt=0,f[M],a[M],b[M];
    void ad(ll x,ll y){
        cnt++;
        edge[cnt].nex=f[x];
        edge[cnt].v=y;
        f[x]=cnt;
    }
    void bfs(){
        queue<ll>ss;
        ss.push(1);
        while(ss.empty()!=1){
        int az=ss.front();
        ll k=f[az];
        while(k!=-1){
        int x=edge[k].v;
        if(d[x]==-1){d[x]=d[az]+1;ss.push(x);}
        k=edge[k].nex;
        }
        ss.pop();
        }
    }
    ll js[M+1];
    int main()
    {    //freopen("p.in","r",stdin);
        cin>>n>>m>>k;
        memset(f,-1,sizeof(f));
        for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        ad(a[i],b[i]);
        ad(b[i],a[i]);
        }
        memset(d,-1,sizeof(d));
        d[1]=0;
        bfs();
        vector<ll>q[m+3];
        for(int i=1;i<=m;i++){
        if(d[a[i]]==d[b[i]]+1)q[a[i]].push_back(i);
        if(d[b[i]]==d[a[i]]+1)q[b[i]].push_back(i);
        }
        for(int i=1;i<=n;i++)js[i]=0;
        vector<string>ans;
        for(int i=1;i<=k;i++){
        string s(m,'0');
        tot++;
        bool az=1;
        for(int j=2;j<=n;j++){
        int x=q[j][js[j]];
        s[x-1]='1';
        }
        //for(int j=0;j<m;j++)cout<<s[j];
        //cout<<endl;
        for(int j=1;j<=n;j++)
        if(js[j]+1<q[j].size()){
            az=0;
            js[j]++;
            break;
        } else js[j]=0;
        ans.push_back(s);
        //cout<<s<<endl;
    //    cout<<q[1][0]<<endl;
        if(az)break;
        }
        cout<<tot<<endl;
        for(int i=0;i<tot;i++)
        cout<<ans[i]<<endl;
        return 0;
    }
    View Code
    戒骄戒躁
  • 相关阅读:
    RPM包校验和提取
    RPM包查询
    Find命令简介
    无法启动配置好的虚拟机
    文档发布至博客操作说明
    VMware Virtual Machine安装报错解决1
    python create home dircetory
    Centos7/Active Directory authentication using nss-pam-ldapd
    java try后面括号的作用
    vps上搭建jupyter notebook远程服务
  • 原文地址:https://www.cnblogs.com/lxzl/p/9649817.html
Copyright © 2011-2022 走看看