Submission #634817

#TimeUsernameProblemLanguageResultExecution timeMemory
634817mdn2002Robot (JOI21_ho_t4)C++14
34 / 100
3069 ms69020 KiB
#include<bits/stdc++.h> using namespace std; struct edg { int a , b , c , p , ind; }; struct edgg { int b , c , p , ind; }; long long n , m , dp [600005]; vector < edgg > gr [100005]; unordered_map < int , long long > sumcol [200005]; vector < edg > edgs; int main () { scanf ( "%lld%lld" , &n , &m ); for ( int i = 1 ; i <= n ; i ++ ) { edgs . push_back ( { i , 0 , 0 , 0 , i - 1 } ); } for ( int i = 0 ; i < m ; i ++ ) { long long x , y , c , p; scanf ( "%lld%lld%lld%lld" , &x , &y , &c , &p ); gr [y] . push_back ( { x , c , p , edgs . size () } ); edgs . push_back ( { x , y , c , p , edgs . size () } ); gr [x] . push_back ( { y , c , p , edgs . size () } ); edgs . push_back ( { y , x , c , p , edgs . size () } ); sumcol [x][c] += p; sumcol [y][c] += p; } for ( int i = 0 ; i <= n + m + m + 1 ; i ++ ) dp [i] = 1e16; dp [0] = 0; priority_queue < pair < long long , int > > q; q . push ( { 0 , 0 } ); long long ans = 1e16; while ( q . size () ) { pair < long long , int > p = q . top (); q . pop (); int ind = p . second; if ( dp [ind] != - p . first ) continue; int x = edgs [ind] . a , last = edgs [ind] . b; if ( x == n ) ans = min ( ans , dp [ind] ); for ( auto uu : gr [x] ) { long long u = uu . b , c = uu . c , p = uu . p; long long sum = sumcol [x][c]; sum -= p; if ( last && edgs [ind] . c == c ) sum -= edgs [ind] . p; int indd = u - 1; if ( dp [ind] + sum < dp [indd] ) { dp [indd] = dp [ind] + sum; q . push ( { - dp [indd] , indd } ); } indd = uu . ind; if ( dp [ind] + p < dp [indd] ) { dp [indd] = dp [ind] + p; q . push ( { - dp [indd] , indd } ); } } } if ( ans == 1e16 ) printf ( "-1" ); else printf ( "%lld" , ans ); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:27:32: warning: narrowing conversion of 'x' from 'long long int' to 'int' [-Wnarrowing]
   27 |         gr [y] . push_back ( { x , c , p , edgs . size () } );
      |                                ^
Main.cpp:27:36: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   27 |         gr [y] . push_back ( { x , c , p , edgs . size () } );
      |                                    ^
Main.cpp:27:40: warning: narrowing conversion of 'p' from 'long long int' to 'int' [-Wnarrowing]
   27 |         gr [y] . push_back ( { x , c , p , edgs . size () } );
      |                                        ^
Main.cpp:27:56: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   27 |         gr [y] . push_back ( { x , c , p , edgs . size () } );
      |                                            ~~~~~~~~~~~~^~
Main.cpp:28:30: warning: narrowing conversion of 'x' from 'long long int' to 'int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                              ^
Main.cpp:28:34: warning: narrowing conversion of 'y' from 'long long int' to 'int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                                  ^
Main.cpp:28:38: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                                      ^
Main.cpp:28:42: warning: narrowing conversion of 'p' from 'long long int' to 'int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                                          ^
Main.cpp:28:58: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , y , c , p , edgs . size () } );
      |                                              ~~~~~~~~~~~~^~
Main.cpp:30:32: warning: narrowing conversion of 'y' from 'long long int' to 'int' [-Wnarrowing]
   30 |         gr [x] . push_back ( { y , c , p , edgs . size () } );
      |                                ^
Main.cpp:30:36: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   30 |         gr [x] . push_back ( { y , c , p , edgs . size () } );
      |                                    ^
Main.cpp:30:40: warning: narrowing conversion of 'p' from 'long long int' to 'int' [-Wnarrowing]
   30 |         gr [x] . push_back ( { y , c , p , edgs . size () } );
      |                                        ^
Main.cpp:30:56: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   30 |         gr [x] . push_back ( { y , c , p , edgs . size () } );
      |                                            ~~~~~~~~~~~~^~
Main.cpp:31:30: warning: narrowing conversion of 'y' from 'long long int' to 'int' [-Wnarrowing]
   31 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                              ^
Main.cpp:31:34: warning: narrowing conversion of 'x' from 'long long int' to 'int' [-Wnarrowing]
   31 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                                  ^
Main.cpp:31:38: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   31 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                                      ^
Main.cpp:31:42: warning: narrowing conversion of 'p' from 'long long int' to 'int' [-Wnarrowing]
   31 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                                          ^
Main.cpp:31:58: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   31 |         edgs . push_back ( { y , x , c , p , edgs . size () } );
      |                                              ~~~~~~~~~~~~^~
Main.cpp:16:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf ( "%lld%lld" , &n , &m );
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf ( "%lld%lld%lld%lld" , &x , &y , &c , &p );
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...