Submission #50274

#TimeUsernameProblemLanguageResultExecution timeMemory
50274SerejadexXxFerries (NOI13_ferries)C++14
40 / 40
335 ms63348 KiB
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm> #include <queue> #include <iostream> using namespace std; vector<pair<pair<int, int>, int> > r; vector<int> ne; vector<int> pr; vector<int> d; vector<int> u; vector<vector<int>> q; vector<int> q_u; int ferries(int N, int M, int * A, int * B, int * C) { r.clear(); d.clear(); u.clear(); pr.clear(); pr.assign(N + 1, -1); ne.clear(); ne.assign(M + 1, 0); q.clear(); q_u.clear(); for (int i = 0; i < N; i++) { vector<int> w; q.push_back(w); q_u.push_back(0); } for (int i = 0; i < M; i++) { A[i]--; B[i]--; ne[i] = pr[B[i]]; pr[B[i]] = i; q[A[i]].push_back(C[i]); } for (int i = 0; i < N; i++) { sort(q[i].begin(), q[i].end()); reverse(q[i].begin(), q[i].end()); } for (int i = 0; i < N; i++) { d.push_back(2000000000); u.push_back(0); } d[N - 1] = 0; priority_queue<pair<int, int>> qq; qq.push(make_pair(-d[N - 1], N - 1)); while (!qq.empty()) { int v = qq.top().second; qq.pop(); if (u[v]) { continue; } u[v] = 1; for (int i = pr[v]; i >= 0; i = ne[i]) { int to = A[i]; if (u[to] == 0) { int val = d[v] + q[to][q_u[to]++]; //cout << v << " " << to << " " << val << " " << endl; if (val < d[to]) { d[to] = val; qq.push(make_pair(-d[to], to)); } } } } return (d[0]); } int AA[300005], BB[300005], CC[300005]; int main() { //------------------------------------ // Read input //----------------------------------- int M, N, i; scanf("%d%d", &M, &N); for (i = 0; i<N; i++) { scanf("%d%d%d", &AA[i], &BB[i], &CC[i]); } printf("%d\n", ferries(M, N, AA, BB, CC)); // system("pause"); return 0; }

Compilation message (stderr)

ferries.cpp: In function 'int main()':
ferries.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &M, &N);
     ~~~~~^~~~~~~~~~~~~~~~
ferries.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &AA[i], &BB[i], &CC[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...