2 条题解

  • 3
    @ 2022-7-27 15:28:03

    赞同一楼(其实是题解摸了)

    #include<bits/stdc++.h>
    using namespace std;
    struct edge
    {
        int u , v ;
    };
    int n , m , c , s[ 100001 ] , ln[ 100001 ] ;
    vector<edge> a[ 100001 ] ;
    void tp()
    {
        queue<int> q ;
        for( int i = 1 ; i <= n ; i ++ )
        {
            if( !ln[ i ] ) q.push( i ) ;
        }
        while( !q.empty() )
        {
            int now = q.front() ;
            q.pop() ;
            for( int i = 0 ; i < a[ now ].size() ; i ++ )
            {
                int w = a[ now ][ i ].u ;
                if( -- ln[ w ] == 0 )
                {
                    q.push( w ) ;
                }
                s[ w ] = max( s[ w ] , s[ now ] + a[ now ][ i ].v ) ;
            }
        }
    }
    int main()
    {
        ios::sync_with_stdio( 0 ) ;
        cin.tie( 0 ) ;
        cin >> n >> m >> c ;
        for( int i = 1 ; i <= n ; i ++ ) cin >> s[ i ] ;
        for( int i = 1 ; i <= c ; i ++ )
        {
            int t1 , t2 , t3 ;
            cin >> t1 >> t2 >> t3 ;
            a[ t1 ].push_back( ( edge ){ t2 , t3 } ) ;
            ln[ t2 ] ++ ;
        }
        tp() ;
        for( int i = 1 ; i <= n ; i ++ ) cout << s[ i ] << "\n" ;
        return 0;
    }
    
    • 1
      @ 2022-7-27 0:21:35

      拓扑 + 递推

      • 1

      信息

      ID
      1958
      时间
      1000ms
      内存
      256MiB
      难度
      2
      标签
      (无)
      递交数
      47
      已通过
      31
      上传者