• 邻接表存图


    #include<iostream>
    #include<cstring>
    #include<string>
    #include<map>
    #include<vector>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<algorithm>
    using namespace std;
    # define inf 0x3f3f3f3f
    # define maxn 100005
    using namespace std;
    int u[10],v[10],w[10];
    struct node
    {
        int head;
        int next;
    } q[100];
    int main()
    {
        int n,m;
        while(cin>>n>>m)
        {
            for(int i=1; i<=n; i++)
            {
                q[i].head=-1;
            }
            for(int i=1; i<=m; i++)
            {
                cin>>u[i]>>v[i]>>w[i];
                q[i].next=q[u[i]].head;
                q[u[i]].head=i;
            }
            for(int i=1; i<=n; i++)
            {
                int t=q[i].head;
                while(t!=-1)
                {
                    cout<<u[t]<<" "<<v[t]<<" "<<w[t]<<endl;
                    t=q[t].next;
                }
            }
            return 0;
        }
    }


  • 相关阅读:
    JS
    JS
    JS
    CSS
    CSS
    CSS
    NPOI导出自动换行效果
    Httpcookie的简单应用
    前台JS设置Cookies后台读取刚设置的Cookies
    SQL SERVER 如何调试存储过程
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10263005.html
Copyright © 2020-2023  润新知