# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
95274 |
2019-01-29T10:48:20 Z |
karma |
Ferries (NOI13_ferries) |
C++11 |
|
267 ms |
32044 KB |
#include<bits/stdc++.h>
#define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName "test"
#define ll long long
#define ld long double
#define ull unsigned long long
#define Print(x) cerr << #x << "is " << x << '\n';
#define pb push_back
#define X first
#define Y second
//#define Karma
using namespace std;
template<typename T> inline void Cin(T &x)
{
char c;
T sign = 1;
x = 0;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') sign = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}
typedef pair<ll, int> pii;
const int N = 3e5 + 7;
const ll oo = 1e18 + 7;
vector<int> a[N];
priority_queue<ll> c[N];
priority_queue<pii, vector<pii>, greater<pii>> pq;
int n, m, u, v;
ll w, d[N];
void Enter()
{
Cin(n, m);
while(m --)
{
Cin(u, v, w);
c[u].push(w), a[v].emplace_back(u);
}
}
void Solve()
{
fill_n(d, n + 1, oo);
d[n] = 0;
pq.push({0, n});
while(!pq.empty())
{
pii top = pq.top();
pq.pop();
if(d[top.Y] != top.X) continue;
int u = top.Y;
for(int v: a[u])
{
if(c[v].size())
{
ll w = c[v].top();
c[v].pop();
if(d[v] > d[u] + w)
{
d[v] = d[u] + w;
pq.push({d[v], v});
}
}
}
}
cout << d[1];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef Karma
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
#endif // Karma
Enter();
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16888 KB |
Output is correct |
2 |
Correct |
17 ms |
16888 KB |
Output is correct |
3 |
Correct |
24 ms |
18296 KB |
Output is correct |
4 |
Correct |
122 ms |
30180 KB |
Output is correct |
5 |
Correct |
125 ms |
30188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
16760 KB |
Output is correct |
2 |
Correct |
16 ms |
16936 KB |
Output is correct |
3 |
Correct |
23 ms |
18168 KB |
Output is correct |
4 |
Correct |
64 ms |
23536 KB |
Output is correct |
5 |
Correct |
132 ms |
26232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
18168 KB |
Output is correct |
2 |
Correct |
29 ms |
18140 KB |
Output is correct |
3 |
Correct |
254 ms |
30792 KB |
Output is correct |
4 |
Correct |
225 ms |
31224 KB |
Output is correct |
5 |
Correct |
220 ms |
30372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
31036 KB |
Output is correct |
2 |
Correct |
175 ms |
30940 KB |
Output is correct |
3 |
Correct |
247 ms |
31928 KB |
Output is correct |
4 |
Correct |
232 ms |
32044 KB |
Output is correct |
5 |
Correct |
267 ms |
31988 KB |
Output is correct |