Submission #526941

# Submission time Handle Problem Language Result Execution time Memory
526941 2022-02-16T17:00:05 Z oneloveforever Autobus (COCI22_autobus) C++14
70 / 70
195 ms 8292 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define ii pair<ll,ll>
const ll inf=1e16+7;
const ll M=100;
ll dp[M][M][M];
ll dist[M][M];
ll n,m;
struct node
{
    ll x,used,value;
    node(ll _value=0,ll _x=0,ll _used=0)
    {
        x=_x,used=_used,value=_value;
    }
};
ll calc(ll path,ll x,ll y)
{
    if(x==y)return 0;
    if(!path)return inf;
    if(dp[path][x][y]!=-1)return dp[path][x][y];
    ll ans=inf;
    for(int node=1;node<=n;node++)
    {
        if(dist[x][node]!=inf)ans=min(ans,calc(path-1,node,y)+dist[x][node]);
    }
    dp[path][x][y]=ans;
    return ans;
}
bool minimize(ll &a,ll b)
{
    if(a>b)
    {
        a=b;
        return true;
    }
    return false;
}
int main()
{
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)dist[i][j]=inf;
    }
    for(int i=1;i<=n;i++)dist[i][i]=0;
    for(ll i=1;i<=m;i++)
    {
        ll x,y,value;
        cin>>x>>y>>value;
        minimize(dist[x][y],value);
    }
    ll q,k;
    cin>>k>>q;
    memset(dp,-1,sizeof(dp));
    while(q--)
    {
        ll node_x,node_y;
        cin>>node_x>>node_y;
        ll ans=calc(min(k,n-1),node_x,node_y);
        cout<<(ans>=inf?-1:ans)<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 3 ms 8140 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 4 ms 8140 KB Output is correct
6 Correct 4 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8208 KB Output is correct
2 Correct 12 ms 8140 KB Output is correct
3 Correct 14 ms 8140 KB Output is correct
4 Correct 12 ms 8208 KB Output is correct
5 Correct 14 ms 8140 KB Output is correct
6 Correct 15 ms 8140 KB Output is correct
7 Correct 17 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 3 ms 8140 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 4 ms 8140 KB Output is correct
6 Correct 4 ms 8140 KB Output is correct
7 Correct 30 ms 8216 KB Output is correct
8 Correct 68 ms 8212 KB Output is correct
9 Correct 15 ms 8140 KB Output is correct
10 Correct 57 ms 8212 KB Output is correct
11 Correct 31 ms 8212 KB Output is correct
12 Correct 109 ms 8192 KB Output is correct
13 Correct 98 ms 8136 KB Output is correct
14 Correct 98 ms 8160 KB Output is correct
15 Correct 172 ms 8164 KB Output is correct
16 Correct 126 ms 8132 KB Output is correct
17 Correct 98 ms 8176 KB Output is correct
18 Correct 93 ms 8176 KB Output is correct
19 Correct 191 ms 8132 KB Output is correct
20 Correct 148 ms 8180 KB Output is correct
21 Correct 98 ms 8260 KB Output is correct
22 Correct 108 ms 8132 KB Output is correct
23 Correct 106 ms 8132 KB Output is correct
24 Correct 179 ms 8292 KB Output is correct
25 Correct 99 ms 8112 KB Output is correct
26 Correct 118 ms 8132 KB Output is correct
27 Correct 125 ms 8128 KB Output is correct
28 Correct 120 ms 8172 KB Output is correct
29 Correct 107 ms 8176 KB Output is correct
30 Correct 115 ms 8292 KB Output is correct
31 Correct 143 ms 8164 KB Output is correct
32 Correct 191 ms 8168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 3 ms 8140 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 4 ms 8140 KB Output is correct
6 Correct 4 ms 8140 KB Output is correct
7 Correct 11 ms 8208 KB Output is correct
8 Correct 12 ms 8140 KB Output is correct
9 Correct 14 ms 8140 KB Output is correct
10 Correct 12 ms 8208 KB Output is correct
11 Correct 14 ms 8140 KB Output is correct
12 Correct 15 ms 8140 KB Output is correct
13 Correct 17 ms 8172 KB Output is correct
14 Correct 30 ms 8216 KB Output is correct
15 Correct 68 ms 8212 KB Output is correct
16 Correct 15 ms 8140 KB Output is correct
17 Correct 57 ms 8212 KB Output is correct
18 Correct 31 ms 8212 KB Output is correct
19 Correct 109 ms 8192 KB Output is correct
20 Correct 98 ms 8136 KB Output is correct
21 Correct 98 ms 8160 KB Output is correct
22 Correct 172 ms 8164 KB Output is correct
23 Correct 126 ms 8132 KB Output is correct
24 Correct 98 ms 8176 KB Output is correct
25 Correct 93 ms 8176 KB Output is correct
26 Correct 191 ms 8132 KB Output is correct
27 Correct 148 ms 8180 KB Output is correct
28 Correct 98 ms 8260 KB Output is correct
29 Correct 108 ms 8132 KB Output is correct
30 Correct 106 ms 8132 KB Output is correct
31 Correct 179 ms 8292 KB Output is correct
32 Correct 99 ms 8112 KB Output is correct
33 Correct 118 ms 8132 KB Output is correct
34 Correct 125 ms 8128 KB Output is correct
35 Correct 120 ms 8172 KB Output is correct
36 Correct 107 ms 8176 KB Output is correct
37 Correct 115 ms 8292 KB Output is correct
38 Correct 143 ms 8164 KB Output is correct
39 Correct 191 ms 8168 KB Output is correct
40 Correct 25 ms 8140 KB Output is correct
41 Correct 71 ms 8208 KB Output is correct
42 Correct 21 ms 8128 KB Output is correct
43 Correct 99 ms 8140 KB Output is correct
44 Correct 32 ms 8160 KB Output is correct
45 Correct 150 ms 8192 KB Output is correct
46 Correct 99 ms 8176 KB Output is correct
47 Correct 146 ms 8164 KB Output is correct
48 Correct 112 ms 8164 KB Output is correct
49 Correct 190 ms 8124 KB Output is correct
50 Correct 108 ms 8244 KB Output is correct
51 Correct 123 ms 8188 KB Output is correct
52 Correct 93 ms 8168 KB Output is correct
53 Correct 192 ms 8168 KB Output is correct
54 Correct 99 ms 8168 KB Output is correct
55 Correct 103 ms 8172 KB Output is correct
56 Correct 182 ms 8204 KB Output is correct
57 Correct 195 ms 8208 KB Output is correct
58 Correct 99 ms 8160 KB Output is correct
59 Correct 142 ms 8188 KB Output is correct
60 Correct 174 ms 8172 KB Output is correct
61 Correct 195 ms 8124 KB Output is correct
62 Correct 95 ms 8168 KB Output is correct
63 Correct 117 ms 8180 KB Output is correct
64 Correct 124 ms 8176 KB Output is correct
65 Correct 192 ms 8132 KB Output is correct