제출 #1306242

#제출 시각아이디문제언어결과실행 시간메모리
1306242tntToll (BOI17_toll)C++20
8 / 100
3094 ms7052 KiB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

#define pb push_back                    
#define ll long long
#define f first
#define s second
#define sz(v) int(v.size())
#define all(v) v.begin(),v.end()

int mod =  1e9 + 7;
const int N = 50000 + 100,N1 = 5000;
const int inf = 1e18;
vector <pair<int,int>> g[N];
ll d[N];
void solve(){
    int k,n,m,q,s,f;
    cin >> k >> n >> m >> q;
    for(int i = 0; i <= n; i++)d[i] = inf;
    for(int i = 1; i <= m; i++){
        int u,v,w;
        cin >>u >> v >> w;
        g[u].pb({v,w});
    }
    set <pair <ll,int>> st;
    set <int> st1;
    while(q--){
        cin >> s >> f;
        st.insert({0,s});
        d[s] = 0;
        while(!st.empty()){
            auto u = (*st.begin()).s;
            st1.insert(u);
            st.erase(st.begin());
            for(auto [to,w] : g[u]){
                if(d[to] > d[u] + w){
                    st.erase({d[to],to});
                    d[to] = d[u] + w;
                    st.insert({d[to],to});
                }
            }
        }
        cout << (d[f] == inf ? -1 : d[f]) << '\n';
        while(!st1.empty()){
            d[*st1.begin()] = inf;
            st1.erase(st1.begin());
        }
    }
}

signed main(){
    //freopen("time.in", "r", stdin);
    //freopen("time.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t1 = 1;
    while(t1--){
    	solve(); 
    }
}  

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

toll.cpp:15:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int inf = 1e18;
      |                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...