stl版的各种模板

最近学STL的时候就想把以前需要手操数据结构的模板再写一遍……话不多说,模板慢慢更新,先从拓扑排序开始。

//临接表的拓扑
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<queue>
using namespace std;
queue<int>dui;
const int MAXX=10050;
inline int read()
{
    int x=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')ff=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*ff;
}
struct node
{
    int y,next,v;
}e[MAXX];
int len=0;
int lin[MAXX];
void inset(int xx,int yy,int vv)
{
    e[++len].y=lin[xx];
    lin[xx]=len;
    e[len].next=yy;
    e[len].v=vv;
}
int id[MAXX];
int n,m;
void init()
{
    n=read();
    m=read();
    for(int i=1;i<=m;i++)
    {
        int x1,x2,x3;
        x1=read();
        x2=read();
        x3=read();
        id[x2]++;
        inset(x1,x2,x3);
    }
}
void topsort()
{
    for(int i=1;i<=n;i++)
    {
        if(id[i]==0)
        {
            dui.push(i);
        }
    }
    while(!dui.empty())
    {
        int te=dui.front();
        cout<<te<<' ';
        dui.pop();
        int tn=lin[te];
        for(int i=tn;i;i=e[i].y)
        {
            int tmp=e[i].next;
            id[tmp]--;
            if(id[tmp]==0)
            {
                dui.push(e[i].next);
            }
        }
    }
}
int main()
{
   // freopen("add.in","r",stdin);
    init();
    topsort();
    cout<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值