# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
545086 |
2022-04-03T14:20:12 Z |
Soul234 |
Ferries (NOI13_ferries) |
C++14 |
|
234 ms |
20168 KB |
#include<bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
const int MX = 1e5+5;
int N, M;
vi adj[MX];
V<ll> Ws[MX];
ll d[MX];
tcT> bool ckmin(T&a, const T&b) {
return b < a ? a = b, 1 : 0;
}
void solve() {
cin>>N>>M;
F0R(i,M) {
ll u,v,c; cin>>u>>v>>c;
adj[v].pb(u);
Ws[u].pb(c);
}
FOR(i,1,N+1) sort(all(Ws[i]));
pqg<pair<ll,int>> pq;
memset(d, 0x3f, sizeof d);
pq.push({d[N] = 0, N});
while(sz(pq)) {
ll du = pq.top().first; int u = pq.top().second;
pq.pop();
if(du != d[u]) continue;
each(v, adj[u]) {
if(ckmin(d[v], d[u] + Ws[v].back())) {
pq.push({d[v], v});
}
Ws[v].pop_back();
}
}
cout << d[1] << nl;
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-->0) {
solve();
}
return 0;
}
Compilation message
ferries.cpp: In function 'void setIO(std::string)':
ferries.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ferries.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5816 KB |
Output is correct |
2 |
Correct |
4 ms |
5844 KB |
Output is correct |
3 |
Correct |
10 ms |
7128 KB |
Output is correct |
4 |
Correct |
116 ms |
18408 KB |
Output is correct |
5 |
Correct |
102 ms |
18328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
5 ms |
5892 KB |
Output is correct |
3 |
Correct |
12 ms |
7148 KB |
Output is correct |
4 |
Correct |
55 ms |
12008 KB |
Output is correct |
5 |
Correct |
84 ms |
14348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6996 KB |
Output is correct |
2 |
Correct |
14 ms |
7008 KB |
Output is correct |
3 |
Correct |
186 ms |
18916 KB |
Output is correct |
4 |
Correct |
213 ms |
19276 KB |
Output is correct |
5 |
Correct |
232 ms |
18648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
18956 KB |
Output is correct |
2 |
Correct |
213 ms |
18880 KB |
Output is correct |
3 |
Correct |
219 ms |
20096 KB |
Output is correct |
4 |
Correct |
202 ms |
20100 KB |
Output is correct |
5 |
Correct |
234 ms |
20168 KB |
Output is correct |