Menu

Investigation | CSES - Algoritmit ongelmanratkaisussa
📰

Investigation | CSES - Algoritmit ongelmanratkaisussa

DEV Community: cpp·Guhan M·6 days ago
#Iq0MTBKn
#devtocpp#devto#dev#include#dist
Long article (484 words) — no AI summary yet.
Reading 0:00
15s threshold

Problem: https://cses.fi/alon/task/1202

#include <iostream> #include <vector> #include <queue> #include <utility>

using namespace std ;

const int kMod = 1e9 + 7 ; const long long INF = 1e18 ;

int main ( ) { ios_base :: sync_with_stdio ( false ) ; cin . tie ( nullptr ) ;

int n , m ; cin >> n >> m ;

vector < vector < pair < int , long long >>> graph ( n + 1 ) ; for ( int i = 0 ; i < m ; i ++ ) { int a , b ; long long c ; cin >> a >> b >> c ; graph [ a ] . push_back ( { b , c } ) ; }

vector < long long > dist ( n + 1 , INF ) ; vector < long long > ways ( n + 1 , 0 ) ; vector < long long > minFlights ( n + 1 , INF ) ; vector < long long > maxFlights ( n + 1 , 0 ) ;

dist [ 1 ] = 0 ; ways [ 1 ] = 1 ; minFlights [ 1 ] = 0 ; maxFlights [ 1 ] = 0 ;

priority_queue < pair < long long , int > , vector < pair < long long , int >> , greater <>> pq ; pq . push ( { 0 , 1 } ) ;

while ( ! pq . empty ( ) ) { auto [ d , u ] = pq . top ( ) ; pq .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.