Submission #472553

#TimeUsernameProblemLanguageResultExecution timeMemory
472553Blobo2_Blobo2Toll (BOI17_toll)C++14
18 / 100
3097 ms6080 KiB
/* Editor: Abdelrahman Hossam Nickname: Blobo2_Blobo2 IOI next year isA :) */ #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops") #include<bits/stdc++.h> using namespace std; //#define int long long #define endl "\n" #define all(v) v.begin(),v.end() #define gen(arr,n,nxt) generate(arr,arr+n,nxt) #define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0); #define EPS 0.00000001 const int mo=1e9+7,INF=1e9; int nxt(){int x;cin>>x;return x;} vector<pair<int,int> >adj[50001]; int n; inline void dijkstra(int s, vector<long long> & d) { d.assign(n, INF); d[s] = 0; using pii = pair<long long, int>; priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, s}); while (!q.empty()) { int v = q.top().second; int d_v = q.top().first; q.pop(); if (d_v != d[v]) continue; for (auto edge : adj[v]) { int to = edge.first; int len = edge.second; if (d[v] + len < d[to]) { d[to] = d[v] + len; q.push({d[to], to}); } } } } inline long long dijkstra2(int s,int to) { vector<long long>d; d.assign(n, INF); d[s] = 0; using pii = pair<long long, int>; priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, s}); while (!q.empty()) { int v = q.top().second; long long d_v = q.top().first; q.pop(); if (d_v != d[v]) continue; if(v == to) return d_v; for (auto edge : adj[v]) { int to = edge.first; int len = edge.second; if (d[v] + len < d[to]) { d[to] = d[v] + len; q.push({d[to], to}); } } } return INF; } signed main(){ Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty //freopen("in.txt","r",stdin); int k=nxt(); n=nxt(); int m=nxt(),qu=nxt(); for(int i=0;i<m;i++){ int x = nxt(),y=nxt(),c= nxt(); adj[x].push_back({y,c}); } unordered_set<int>from; map<pair<int,int>,int>finalAns; vector<pair<int,int> >v; vector<int>ans[n]; while(qu--){ v.push_back({nxt(),nxt()}); finalAns[v.back()] = -2; ans[v.back().first].push_back(v.back().second); from.insert(v.back().first); } for(auto x:from){ if(ans[x].size() <= 10)continue; vector<long long>d; dijkstra(x,d); for(auto y:ans[x]) finalAns[{x,y}] = (d[y] == INF?-1:d[y]); } for(auto x:v){ if(finalAns[x] == -2){ int zh2t = dijkstra2(x.first,x.second); cout<<(zh2t == INF?-1:zh2t)<<endl; } else cout<<finalAns[x]<<endl; } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:79:9: warning: unused variable 'k' [-Wunused-variable]
   79 |     int k=nxt();
      |         ^
#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...