Submission #226855

# Submission time Handle Problem Language Result Execution time Memory
226855 2020-04-25T14:40:46 Z kimbj0709 Ferries (NOI13_ferries) C++14
40 / 40
307 ms 21876 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100050
#define pii pair<int,int>
#define f first
#define s second
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int no_of_vertex,no_of_edge;
  int input1,input2,input3;
  vector<vector<int> > adj(maxn);
  cin >> no_of_vertex >> no_of_edge;
  vector<vector<int> > num(maxn);
  for(int i=0;i<no_of_edge;i++){
    cin >> input1 >> input2 >> input3;
    adj[input2].push_back(input1);
    num[input1].push_back(input3);
  }
  vector<int> dist(maxn,INT_MAX);
  dist[no_of_vertex] = 0;
  for(int i=0;i<maxn;i++){
    sort(num[i].begin(),num[i].end());
  }
  priority_queue<pii,vector<pii>,greater<pii> > q1;
  q1.push({0,no_of_vertex});
  while(q1.size()!=0){
    pair<int,int> a = q1.top();
    q1.pop();
    if(dist[a.s]!=a.first){
      continue;
    }
    for(auto k:adj[a.second]){
      if(dist[k]>a.first+num[k].back()){
        dist[k] = a.first+num[k].back();
        q1.push({dist[k],k});
      }
      num[k].pop_back();
    }
  }
  /*for(int i=1;i<=no_of_vertex;i++){
    cout << dist[i] << " ";
  }
  cout << endl;*/
  cout << dist[1];
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5888 KB Output is correct
2 Correct 9 ms 6016 KB Output is correct
3 Correct 18 ms 7296 KB Output is correct
4 Correct 138 ms 18784 KB Output is correct
5 Correct 131 ms 18912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5888 KB Output is correct
2 Correct 8 ms 5888 KB Output is correct
3 Correct 17 ms 7296 KB Output is correct
4 Correct 60 ms 12400 KB Output is correct
5 Correct 108 ms 14752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 7296 KB Output is correct
2 Correct 21 ms 7296 KB Output is correct
3 Correct 244 ms 20600 KB Output is correct
4 Correct 284 ms 21112 KB Output is correct
5 Correct 268 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 20600 KB Output is correct
2 Correct 262 ms 20720 KB Output is correct
3 Correct 289 ms 21724 KB Output is correct
4 Correct 307 ms 21876 KB Output is correct
5 Correct 286 ms 21748 KB Output is correct