# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
701763 |
2023-02-22T05:06:56 Z |
tamthegod |
Ceste (COCI17_ceste) |
C++17 |
|
3 ms |
852 KB |
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e14;
int n, m;
struct TAdj
{
int v, w, c;
};
vector<TAdj> adj[maxN];
unordered_map<int, int> d[maxN];
int tmp[maxN];
struct TPQRect
{
int vertex, time, dlab;
bool operator < (const TPQRect& other) const
{
return other.dlab < dlab;
}
bool Valid() const
{
return d[vertex][time] == dlab;
}
};
void ReadInput()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
int u, v, w, c;
cin >> u >> v >> w >> c;
adj[u].pb({v, w, c});
adj[v].pb({u, w, c});
}
}
void Dijkstra()
{
memset(tmp, 3, sizeof tmp);
d[1][0] = 0;
priority_queue<TPQRect> pq;
pq.push({1, 0, 0});
while(!pq.empty())
{
TPQRect r = pq.top();
pq.pop();
if(!r.Valid()) continue;
int u = r.vertex, t = r.time;
if(r.dlab > tmp[u]) continue;
tmp[u] = r.dlab;
for(TAdj a : adj[u])
{
if(d[a.v].find(t + a.w) == d[a.v].end() || d[a.v][t + a.w] > d[u][t] + a.c)
{
d[a.v][t + a.w] = d[u][t] + a.c;
pq.push({a.v, t + a.w, d[a.v][t + a.w]});
}
}
}
}
void Solve()
{
Dijkstra();
for(int i=2; i<=n; i++)
{
int res = oo;
for(pair<int, int> v : d[i])
res = min(res, v.fi * v.se);
cout << (res < oo ? res : -1) << '\n';
}
}
int32_t main()
{
// freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |