Submission #546912

# Submission time Handle Problem Language Result Execution time Memory
546912 2022-04-08T20:30:33 Z ala2 Autobus (COCI22_autobus) C++14
30 / 70
1000 ms 31164 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back

using namespace std;
vector<pair<int,int>>v[100100];
const int inf=1e18;
int dp[100][100][1000];
int f(int x,int y,int k)
{
    if(k<0)
      return inf;
    if(x==y)
    {
        return 0;
    }
    if(dp[x][y][k])
        return dp[x][y][k];
    int mn=1e18;
    for(int i=0;i<v[x].size();i++)
    {
        mn=min(mn,v[x][i].second+f(v[x][i].first,y,k-1));
    }
    return dp[x][y][k]=mn;

}
signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int c,o,w;
        cin>>c>>o>>w;
        v[c].pb({o,w});
    }
    int q,k;
    cin>>k>>q;
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(f(x,y,k)<=1e15)
        cout<<f(x,y,k)<<endl;
        else cout<<-1<<endl;
    }

}

Compilation message

Main.cpp: In function 'long long int f(long long int, long long int, long long int)':
Main.cpp:20:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<v[x].size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2784 KB Output is correct
3 Correct 2 ms 2792 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 7 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 22004 KB Output is correct
2 Correct 37 ms 22064 KB Output is correct
3 Correct 25 ms 22128 KB Output is correct
4 Correct 28 ms 22092 KB Output is correct
5 Correct 29 ms 22112 KB Output is correct
6 Correct 32 ms 22308 KB Output is correct
7 Correct 37 ms 22228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2784 KB Output is correct
3 Correct 2 ms 2792 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 7 ms 2772 KB Output is correct
7 Correct 27 ms 23004 KB Output is correct
8 Correct 46 ms 24484 KB Output is correct
9 Correct 29 ms 22132 KB Output is correct
10 Correct 47 ms 23300 KB Output is correct
11 Correct 60 ms 22548 KB Output is correct
12 Correct 140 ms 23724 KB Output is correct
13 Execution timed out 1090 ms 31164 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2784 KB Output is correct
3 Correct 2 ms 2792 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 7 ms 2772 KB Output is correct
7 Correct 22 ms 22004 KB Output is correct
8 Correct 37 ms 22064 KB Output is correct
9 Correct 25 ms 22128 KB Output is correct
10 Correct 28 ms 22092 KB Output is correct
11 Correct 29 ms 22112 KB Output is correct
12 Correct 32 ms 22308 KB Output is correct
13 Correct 37 ms 22228 KB Output is correct
14 Correct 27 ms 23004 KB Output is correct
15 Correct 46 ms 24484 KB Output is correct
16 Correct 29 ms 22132 KB Output is correct
17 Correct 47 ms 23300 KB Output is correct
18 Correct 60 ms 22548 KB Output is correct
19 Correct 140 ms 23724 KB Output is correct
20 Execution timed out 1090 ms 31164 KB Time limit exceeded
21 Halted 0 ms 0 KB -