Submission #526717

# Submission time Handle Problem Language Result Execution time Memory
526717 2022-02-16T02:49:00 Z beepbeepsheep Autobus (COCI22_autobus) C++17
30 / 70
117 ms 3256 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=71;

ll adj[maxn][maxn];
ll dis[maxn][maxn][maxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int i=0;i<maxn;i++){
        for (int j=0;j<maxn;j++){
            adj[i][j]=inf;
        }
        adj[i][i]=0;
    }
    ll n,e,a,b,w;
    cin>>n>>e;
    for (int i=0;i<e;i++){
        cin>>a>>b>>w;
        adj[a][b]=min(adj[a][b],w);
    }
    ll k,y,u,x;
    cin>>k>>y;
    queue<ii> q;
    memset(dis,-1,sizeof(dis));
    for (int a=1;a<=n;a++){
        q.emplace(a,0);
        dis[a][a][0]=0;
        while (q.size()){
            u=q.front().first;
            x=q.front().second;
            q.pop();
            if (x>k) continue;
            for (int i=1;i<=n;i++){
                if (dis[a][i][x+1]!=-1){
                    dis[a][i][x+1]=min(dis[a][i][x+1],dis[a][u][x]+adj[u][i]);
                } else{
                    dis[a][i][x+1]=dis[a][u][x]+adj[u][i];
                    q.emplace(i,x+1);
                } //n
            }
        }//n2
    }
    for (int i=0;i<y;i++){
        ll ans=inf;
        cin>>a>>b;
        for (int i=0;i<=k;i++){
            if (dis[a][b][i]!=-1) ans=min(ans,dis[a][b][i]);
        }
        cout<<(ans==inf?-1:ans)<<endl;
    }//n2
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3148 KB Output is correct
2 Correct 2 ms 3148 KB Output is correct
3 Correct 2 ms 3148 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3148 KB Output is correct
2 Correct 4 ms 3148 KB Output is correct
3 Correct 4 ms 3148 KB Output is correct
4 Correct 4 ms 3148 KB Output is correct
5 Correct 4 ms 3148 KB Output is correct
6 Correct 4 ms 3160 KB Output is correct
7 Correct 4 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3148 KB Output is correct
2 Correct 2 ms 3148 KB Output is correct
3 Correct 2 ms 3148 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
7 Correct 12 ms 3148 KB Output is correct
8 Correct 31 ms 3156 KB Output is correct
9 Correct 4 ms 3148 KB Output is correct
10 Correct 25 ms 3148 KB Output is correct
11 Correct 8 ms 3148 KB Output is correct
12 Correct 26 ms 3148 KB Output is correct
13 Correct 82 ms 3040 KB Output is correct
14 Correct 83 ms 3040 KB Output is correct
15 Correct 114 ms 3036 KB Output is correct
16 Correct 94 ms 3032 KB Output is correct
17 Correct 87 ms 3024 KB Output is correct
18 Correct 82 ms 3024 KB Output is correct
19 Correct 117 ms 3156 KB Output is correct
20 Correct 111 ms 3140 KB Output is correct
21 Correct 99 ms 3160 KB Output is correct
22 Correct 95 ms 3164 KB Output is correct
23 Correct 89 ms 3164 KB Output is correct
24 Correct 106 ms 3168 KB Output is correct
25 Correct 86 ms 3140 KB Output is correct
26 Correct 91 ms 3140 KB Output is correct
27 Correct 102 ms 3156 KB Output is correct
28 Correct 93 ms 3140 KB Output is correct
29 Correct 90 ms 3168 KB Output is correct
30 Correct 88 ms 3168 KB Output is correct
31 Correct 102 ms 3152 KB Output is correct
32 Incorrect 116 ms 3256 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3148 KB Output is correct
2 Correct 2 ms 3148 KB Output is correct
3 Correct 2 ms 3148 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
7 Correct 5 ms 3148 KB Output is correct
8 Correct 4 ms 3148 KB Output is correct
9 Correct 4 ms 3148 KB Output is correct
10 Correct 4 ms 3148 KB Output is correct
11 Correct 4 ms 3148 KB Output is correct
12 Correct 4 ms 3160 KB Output is correct
13 Correct 4 ms 3148 KB Output is correct
14 Correct 12 ms 3148 KB Output is correct
15 Correct 31 ms 3156 KB Output is correct
16 Correct 4 ms 3148 KB Output is correct
17 Correct 25 ms 3148 KB Output is correct
18 Correct 8 ms 3148 KB Output is correct
19 Correct 26 ms 3148 KB Output is correct
20 Correct 82 ms 3040 KB Output is correct
21 Correct 83 ms 3040 KB Output is correct
22 Correct 114 ms 3036 KB Output is correct
23 Correct 94 ms 3032 KB Output is correct
24 Correct 87 ms 3024 KB Output is correct
25 Correct 82 ms 3024 KB Output is correct
26 Correct 117 ms 3156 KB Output is correct
27 Correct 111 ms 3140 KB Output is correct
28 Correct 99 ms 3160 KB Output is correct
29 Correct 95 ms 3164 KB Output is correct
30 Correct 89 ms 3164 KB Output is correct
31 Correct 106 ms 3168 KB Output is correct
32 Correct 86 ms 3140 KB Output is correct
33 Correct 91 ms 3140 KB Output is correct
34 Correct 102 ms 3156 KB Output is correct
35 Correct 93 ms 3140 KB Output is correct
36 Correct 90 ms 3168 KB Output is correct
37 Correct 88 ms 3168 KB Output is correct
38 Correct 102 ms 3152 KB Output is correct
39 Incorrect 116 ms 3256 KB Output isn't correct
40 Halted 0 ms 0 KB -