제출 #925874

#제출 시각아이디문제언어결과실행 시간메모리
925874CutebolCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
1035 ms33824 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; bool YES(bool f){ if(f) cout << "Yes\n" ; else cout << "No\n" ; return f ; } void YES(){YES(1);} void NO(){YES(0);} void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} //#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0); #define int long long #define ld long double #define pii pair <int , int> #define all(x) x.begin() , x.end() #define ff first #define ss second #define endl '\n' const int N = 2e5 + 5 ; const int inf = 1e16 ; const int mod = 1e9 + 8 ; const double eps = 1e-8 ; int binpow( int a , int b ){ if ( b == 0 ) return 1 ; int x = binpow ( a , b/2 ) ; if ( !(b%2) ) return (x*x) ; return (x*x*a) ; } template <class T> bool chmax( T& x , const T& y ){ bool f = 0 ; if ( x < y ) x = y , f = 1 ; return f ; } template <class T> bool chmin( T &x , const T &y ){ bool f = 0 ; if ( x > y ) x = y , f = 1 ; return f ; } //code int n , m , a , b , c , d , ans ; vector <pii> g[N] ; int dis[N][2] , dp[2][N] , ds[N] ; bool vis[N] ; void dijkstra( int s , int f ){ memset( vis , 0 , sizeof(vis)) ; set <pii> st ; st.insert({0,s}) ; while ( st.size() ){ int v = st.begin()->ss ; int d = st.begin()->ff ; st.erase(st.begin()) ; if (!vis[v]){ vis[v] = 1 ; dis[v][f] = d ; for ( auto to : g[v] ) st.insert({d+to.ss,to.ff}) ; } } } void calc ( int a , int b ){ memset ( dp[0] , 0x3F , sizeof(dp[0]) ) ; memset ( dp[1] , 0x3F , sizeof(dp[1]) ) ; memset ( vis , 0 , sizeof(vis) ) ; set <pair < int , pii>> st ; st.insert({0,{a,0}}) ; while (st.size()){ int v = st.begin()->ss.ff ; int d = st.begin()->ff ; int p = st.begin()->ss.ss ; st.erase(st.begin()) ; if ( !vis[v] ){ vis[v] = 1 ; ds[v] = d ; dp[0][v] = min ( dp[0][p] , dis[v][0] ) ; dp[1][v] = min ( dp[1][p] , dis[v][1] ) ; for ( auto to : g[v] ) st.insert({d+to.ss,{to.ff,v}}) ; } else if ( d == ds[v] ){ if ( dp[0][v] + dp[1][v] >= min ( dp[0][p] , dis[v][0] ) + min ( dp[1][p] , dis[v][1] ) ){ dp[0][v] = min ( dp[0][p] , dis[v][0] ) ; dp[1][v] = min ( dp[1][0] , dis[v][1] ) ; } } } chmin ( ans , dp[0][b] + dp[1][b] ) ; } void solve(){ cin >> n >> m >> a >> b >> c >> d ; for ( int i = 0 ; i < m ; i ++ ){ int x , y , c ; cin >> x >> y >> c ; g[x].push_back({y,c}) ; g[y].push_back({x,c}) ; } dijkstra( c , 0 ) ; dijkstra( d , 1 ) ; ans = dis[d][0] ; calc(a,b) ; calc(b,a) ; cout << ans ; } signed main(){ //ios ; int t = 1 ; //cin >> t ; while ( t -- ) solve() ; }

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

commuter_pass.cpp: In function 'void fopn(std::string)':
commuter_pass.cpp:10:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:10:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...