제출 #634806

#제출 시각아이디문제언어결과실행 시간메모리
634806mdn2002Robot (JOI21_ho_t4)C++14
34 / 100
3097 ms71340 KiB
#include<bits/stdc++.h> using namespace std; long long n , m , dp [600005]; vector < int > gr [200005]; map < pair < int , int > , long long > col , pri , sumcol , redg; vector < pair < int , int > > edg; int main () { scanf ( "%lld%lld" , &n , &m ); for ( int i = 1 ; i <= n ; i ++ ) { edg . push_back ( { i , 0 } ); redg [ { i , 0 } ] = i - 1; } for ( int i = 0 ; i < m ; i ++ ) { int x , y; scanf ( "%d%d" , &x , &y ); redg [ { y , x } ] = edg . size (); edg . push_back ( { y , x } ); redg [ { x , y } ] = edg . size (); edg . push_back ( { x , y } ); gr [x] . push_back ( y ); gr [y] . push_back ( x ); cin >> col [ { x , y } ] >> pri [ { x , y } ]; col [ { y , x } ] = col [ { x , y } ]; pri [ { y , x } ] = pri [ { x , y } ]; sumcol [ { x , col [ { x , y } ] } ] += pri [ { x , y } ]; sumcol [ { y , col [ { x , y } ] } ] += pri [ { x , y } ]; } 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; int x = edg [ind] . first , last = edg [ind] . second; if ( x == n ) ans = min ( ans , dp [ind] ); for ( auto u : gr [x] ) { long long sum = sumcol [ { x , col [ { x , u } ] } ]; sum -= pri [ { x , u } ]; if ( last && col [ { x , last } ] == col [ { x , u } ] ) sum -= pri [ { x , last } ]; int indd = redg [ { u , 0 } ]; if ( dp [ind] + sum < dp [indd] ) { dp [indd] = dp [ind] + sum; q . push ( { - dp [indd] , indd } ); } indd = redg [ { u , x } ]; if ( dp [ind] + pri [ { x , u } ] < dp [indd] ) { dp [indd] = dp [ind] + pri [ { x , u } ]; q . push ( { - dp [indd] , indd } ); } } } if ( ans == 1e16 ) printf ( "-1" ); else printf ( "%lld" , ans ); }

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

Main.cpp: In function 'int main()':
Main.cpp:9:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf ( "%lld%lld" , &n , &m );
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf ( "%d%d" , &x , &y );
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...