Submission #701669

# Submission time Handle Problem Language Result Execution time Memory
701669 2023-02-21T21:36:13 Z delrey Autobus (COCI22_autobus) C++14
15 / 70
1000 ms 572 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1000000000;
int n, m, k, qn;
vector <pair<int, int> > v[70]; //{{town B, time}
int d[70], t[70];
priority_queue <pair<pair<int, int>, int> > q; //{{distance, time}, town}

int main()
{
    cin>>n>>m;
    for(int i = 0; i < m; i++)
    {
        int a, b, t;
        cin>>a>>b>>t;
        a--;
        b--;
        v[a].push_back({b, t});
    }
    cin>>k>>qn;
    while(qn--)
    {
        int from, to;
        cin>>from>>to;
        from--;
        to--;
        for(int i = 0; i < n; i++)
            d[i] = t[i] = inf;
        q.push({{0, 0}, from});
        while(q.size())
        {
            int dis = -q.top().first.first;
            int tim = -q.top().first.second;
            int a = q.top().second;
            q.pop();
            if(dis > k || t[a] <= tim)
                continue;
            d[a] = dis;
            t[a] = tim;
            if(dis == k)
                continue;
            for(size_t i = 0; i < v[a].size(); i++)
                if(t[a] + v[a][i].second < t[v[a][i].first])
                    q.push({{-(d[a] + 1), -(t[a] + v[a][i].second)}, v[a][i].first});
        }
        /*
        cout<<"d: ";
        for(int i = 0; i < n; i++)
            cout<<d[i]<<" ";
        cout<<endl<<"t: ";
        for(int i = 0; i < n; i++)
            cout<<t[i]<<" ";
        cout<<endl<<"r: ";
        */
        if(t[to] == inf)
            cout<<-1<<endl;
        else
            cout<<t[to]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 320 KB Output is correct
2 Correct 24 ms 316 KB Output is correct
3 Correct 82 ms 452 KB Output is correct
4 Correct 127 ms 340 KB Output is correct
5 Correct 376 ms 392 KB Output is correct
6 Execution timed out 1076 ms 544 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 168 ms 372 KB Output is correct
8 Correct 161 ms 352 KB Output is correct
9 Correct 432 ms 380 KB Output is correct
10 Correct 443 ms 368 KB Output is correct
11 Execution timed out 1080 ms 572 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 11 ms 320 KB Output is correct
8 Correct 24 ms 316 KB Output is correct
9 Correct 82 ms 452 KB Output is correct
10 Correct 127 ms 340 KB Output is correct
11 Correct 376 ms 392 KB Output is correct
12 Execution timed out 1076 ms 544 KB Time limit exceeded
13 Halted 0 ms 0 KB -