Submission #1160013

#TimeUsernameProblemLanguageResultExecution timeMemory
1160013mariaclaraEscape Route (JOI21_escape_route)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef tuple<int,int,int> trio;
typedef pair<ll,int> pii;
const int MAXN = 2e5+5;
const ll INF = 1e18;
const int MOD = 998244353;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

int n, m, q;
ll s, L[100][100], C[100][100], dist[100][100];
vector<int> ans;
vector<trio> query[100];

void pre_calc(int raiz) {
    for(int i = 0; i < n; i++) dist[raiz][i] = -1;
    vector<bool> vis(n);
    dist[raiz][raiz] = 0;

    while(1) {
        ll D = -1;
        int x = -1;
        for(int i = 0; i < n; i++) {
            if(dist[raiz][i] != -1 and !vis[i] and (D == -1 or D > dist[raiz][i])) 
                D = dist[raiz][i], x = i;
        }

        if(x == -1) break;
        vis[x] = 1;

        for(int viz = 0; viz < n; viz++) {
            if(L[x][viz] == 0) continue;
            ll D_viz;
            if(D%s <= C[x][viz] - L[x][viz]) D_viz = D + L[x][viz];
            else D_viz = D + s - D%s + L[x][viz];
            if(dist[raiz][viz] == -1 or dist[raiz][viz] >= D_viz) 
                dist[raiz][viz] = D_viz;
        }
    }
} 

ll dijkstra(int raiz, int fim, ll t) {
    for(int i = 0; i < n; i++) dist[raiz][i] = -1;
    vector<bool> vis(n);
    dist[raiz][raiz] = t;

    while(1) {
        ll D = -1;
        int x = -1;
        for(int i = 0; i < n; i++) {
            if(dist[raiz][i] != -1 and !vis[i] and (D == -1 or D > dist[raiz][i])) 
                D = dist[raiz][i], x = i;
        }

        if(x == -1) break;
        vis[x] = 1;

        for(int viz = 0; viz < n; viz++) {
            if(L[x][viz] == 0) continue;
            ll D_viz;
            if(D%s <= C[x][viz] - L[x][viz]) D_viz = D + L[x][viz];
            else D_viz = D + s - D%s + L[x][viz];
            if(dist[raiz][viz] == -1 or dist[raiz][viz] >= D_viz) 
                dist[raiz][viz] = D_viz;
        }
    }

    return dist[raiz][fim];
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> s >> q;

    while(m--) {
        int a, b;
        ll l, c;
        cin >> a >> b >> l >> c;
        L[a][b] = L[b][a] = l;
        C[a][b] = C[b][a] = c;
    }

    ans.resize(q);
    for(int Q = 0, u, v; Q < q; Q++) {
        ll t;
        cin >> u >> v >> t;
        //query[u].pb({t, v, Q});
        cout << dijkstra(u, v, t) - t << "\n";
    }

    for(int i = 0; i < n; i++) pre_calc(i);

    // for(int i = 0; i < n; i++) {
    //     sort(all(query[i]));
    //     reverse(all(query[i]));
    // }
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccA0r7Sc.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccKWWT0K.o:escape_route.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccA0r7Sc.o: in function `main':
grader.cpp:(.text.startup+0x6e0): undefined reference to `calculate_necessary_time(int, int, long long, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<long long, std::allocator<long long> >, std::vector<long long, std::allocator<long long> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<long long, std::allocator<long long> >)'
collect2: error: ld returned 1 exit status