Submission #1074445

# Submission time Handle Problem Language Result Execution time Memory
1074445 2024-08-25T10:34:15 Z cpptowin Ceste (COCI17_ceste) C++17
160 / 160
395 ms 53164 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
int n,m,minf[maxn],mint[maxn];
vector<array<int,3>> ke[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    fo(i,1,m) 
    {
        int u,v,t,c;
        cin >> u >> v >> t >> c;
        ke[u].push_back({v,t,c});
        ke[v].push_back({u,t,c});
    }
    priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>>q;
    fo(i,2,n) minf[i] = mint[i] = inf;
    q.push({0,0,1});
    int lim = 2000 * 3000;
    while(ss(q))
    {
        auto [du,dt,u] = q.top();
        minimize(minf[u],du * dt);
        q.pop();
        if(mint[u] < dt) continue;
        minimize(mint[u],dt);
        for(auto [v,t,c] : ke[u]) 
        {
            if(dt + t <= lim) q.push({du + c,dt + t,v});
        }
    }
    fo(i,2,n) cout << (minf[i] == inf ? -1 : minf[i]) << '\n';
}

Compilation message

ceste.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main()
      | ^~~~
ceste.cpp: In function 'int main()':
ceste.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ceste.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27228 KB Output is correct
2 Correct 7 ms 27480 KB Output is correct
3 Correct 8 ms 27676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 28884 KB Output is correct
2 Correct 49 ms 31952 KB Output is correct
3 Correct 70 ms 31948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 30540 KB Output is correct
2 Correct 395 ms 53164 KB Output is correct
3 Correct 10 ms 27740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 28340 KB Output is correct
2 Correct 257 ms 40120 KB Output is correct
3 Correct 13 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 28236 KB Output is correct
2 Correct 209 ms 31592 KB Output is correct
3 Correct 180 ms 31688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 30660 KB Output is correct
2 Correct 165 ms 30660 KB Output is correct
3 Correct 233 ms 31848 KB Output is correct