제출 #634828

#제출 시각아이디문제언어결과실행 시간메모리
634828mdn2002Robot (JOI21_ho_t4)C++14
34 / 100
3102 ms86544 KiB
#include<bits/stdc++.h> using namespace std; struct edg { long long a , b , c , p , ind; }; struct edgg { long long 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] ); break; } 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 ); }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:27:56: warning: narrowing conversion of 'edgs.std::vector<edg>::size()' from 'std::vector<edg>::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   27 |         gr [y] . push_back ( { x , 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 'long long int' [-Wnarrowing]
   28 |         edgs . push_back ( { x , 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 'long long int' [-Wnarrowing]
   30 |         gr [x] . push_back ( { y , 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 'long long 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...