답안 #472543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472543 2021-09-13T17:27:32 Z Blobo2_Blobo2 Toll (BOI17_toll) C++14
18 / 100
3000 ms 5912 KB
/*
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];
map<pair<int,int> ,int>mp;
int n;
void dijkstra(int s, vector<int> & d) {
    d.assign(n, INF);
    d[s] = 0;
    using pii = pair<int, 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});
            }
        }
    }
}
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;
    vector<pair<int,int> >v;
    vector<int>ans[n];
    while(qu--){
        v.push_back({nxt(),nxt()});
        ans[v.back().first].push_back(v.back().second);
        from.insert(v.back().first);
    }
    map<pair<int,int>,int>finalAns;
    for(auto x:from){
        vector<int>d;
        dijkstra(x,d);
        for(auto y:ans[x])
            finalAns[{x,y}] = (d[y] == INF?-1:d[y]);
    }
    for(auto x:v)
        cout<<finalAns[x]<<endl;
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:53:9: warning: unused variable 'k' [-Wunused-variable]
   53 |     int k=nxt();
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3066 ms 5412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 5060 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 6 ms 1740 KB Output is correct
8 Correct 7 ms 1728 KB Output is correct
9 Correct 28 ms 5124 KB Output is correct
10 Correct 69 ms 5912 KB Output is correct
11 Correct 52 ms 5020 KB Output is correct
12 Correct 41 ms 5000 KB Output is correct
13 Correct 71 ms 5088 KB Output is correct
14 Correct 44 ms 4036 KB Output is correct
15 Correct 35 ms 3792 KB Output is correct
16 Correct 36 ms 3748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 5 ms 1484 KB Output is correct
8 Correct 12 ms 1484 KB Output is correct
9 Correct 9 ms 1484 KB Output is correct
10 Correct 30 ms 4388 KB Output is correct
11 Correct 278 ms 4368 KB Output is correct
12 Correct 381 ms 5268 KB Output is correct
13 Correct 458 ms 5572 KB Output is correct
14 Correct 387 ms 4864 KB Output is correct
15 Correct 233 ms 3600 KB Output is correct
16 Correct 230 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 5 ms 1484 KB Output is correct
8 Correct 12 ms 1484 KB Output is correct
9 Correct 9 ms 1484 KB Output is correct
10 Correct 30 ms 4388 KB Output is correct
11 Correct 278 ms 4368 KB Output is correct
12 Correct 381 ms 5268 KB Output is correct
13 Correct 458 ms 5572 KB Output is correct
14 Correct 387 ms 4864 KB Output is correct
15 Correct 233 ms 3600 KB Output is correct
16 Correct 230 ms 3532 KB Output is correct
17 Execution timed out 3058 ms 4816 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3066 ms 5412 KB Time limit exceeded
2 Halted 0 ms 0 KB -