Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef vector< ll > vl;
- typedef vector< bool > vb;
- typedef pair<ll , ll> pll;
- typedef vector< pll > vll;
- #define PB push_back
- #define INF ll(4e18)
- #define S second
- #define F first
- vector< vll > al ,al_t;
- vb articulationPoint;
- int n ,m ,s ,e ,cntD;
- vl dfs_num ,dfs_low;
- vector< vl > al2;
- void init()
- {
- al.assign(n ,vll());
- al2.assign(n ,vl());
- al_t.assign(n ,vll());
- cntD = 1;
- dfs_num.assign(n ,0);
- dfs_low.assign(n ,0);
- articulationPoint.assign(n ,false);
- }
- vl Dijkstra()
- {
- vl dist(n ,INF);
- dist[s] = 0;
- priority_queue< pll , vll , greater< pll > > pq;
- pq.push( pll(0ll ,s) );
- while( !pq.empty() )
- {
- ll u = pq.top().S;
- ll d = pq.top().F;
- pq.pop();
- if( d > dist[u] ) continue;
- for(pll v : al[u])
- {
- if( dist[u] + v.S < dist[v.F] )
- {
- dist[v.F] = dist[u] + v.S;
- pq.push( pll(dist[v.F] ,v.F) );
- }
- }
- }
- return dist;
- }
- void BFSreverseGraph(const vl &dist)
- {
- vb vis(n ,false);
- vis[e] = true;
- queue< int > q;
- q.push(e);
- while( !q.empty() )
- {
- int u = q.front(); q.pop();
- for(pll v : al_t[u])
- {
- if( dist[v.F] + v.S == dist[u] )
- {
- al2[u].PB(v.F);
- al2[v.F].PB(u);
- if( !vis[v.F] )
- {
- vis[v.F] = true;
- q.push(v.F);
- }
- }
- }
- }
- }
- void getArticulationPoint(int u ,int p)
- {
- dfs_num[u] = dfs_low[u] = cntD++;
- for(int v : al2[u])
- {
- if( !dfs_num[v] )
- {
- getArticulationPoint(v ,u);
- if( dfs_low[v] >= dfs_num[u] ) articulationPoint[u] = true;
- dfs_low[u] = min(dfs_low[u] ,dfs_low[v]);
- }
- else dfs_low[u] = min(dfs_low[u] ,dfs_num[v]);
- }
- }
- int main()
- {
- scanf("%d%d" ,&n ,&m);
- init();
- for(int i = 0 ; i < m ; i++)
- {
- int u; scanf("%d" ,&u);
- int v; scanf("%d" ,&v);
- ll w; scanf("%lld",&w);
- al [u].PB( pll(v ,w) );
- al_t[v].PB( pll(u ,w) );
- }
- scanf("%d%d" ,&s ,&e);
- vl dist = Dijkstra();
- BFSreverseGraph(dist);
- getArticulationPoint(s ,s);
- articulationPoint[s] = true;
- articulationPoint[e] = true;
- for(int i = 0 ; i < n ; i++)
- if( articulationPoint[i] )
- printf("%d " ,i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement