Guest User

Untitled

a guest
Jun 11th, 2016
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define readFile freopen("input","r",stdin)
  4. #define writeFile freopen("output","w",stdout)
  5. #define fastIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
  6. typedef unsigned long long ull;
  7. typedef long long LL;
  8. typedef pair<long long,long long> ii;
  9. const double eps = 1e-10;
  10. const long long mod = 1e9+7;
  11. const long long INF = 1e17;
  12. const int N = 100001,M = 51;
  13. vector<vector<pair<ii,int> > > G;
  14. long long n,m,a,b,c,d;
  15. ii dp[N];
  16. int main() {
  17.     #ifndef ONLINE_JUDGE
  18.     readFile;
  19. //    writeFile;
  20. #endif
  21.     G.resize(N);
  22.     cin>>n>>m;
  23.     for(int i=1;i<=n;i++){
  24.         cin>>a>>b>>c>>d;
  25.         G[a].push_back(make_pair(make_pair(c,d),b));
  26.     }
  27.     for(int i=1;i<N;i++) dp[i] = make_pair(INF,INF);
  28.     dp[0] = make_pair(0,0);
  29.     for(int i=1;i<=m;i++){
  30.         if (dp[i-1]==make_pair(INF,INF)) continue;
  31.         for(int j=0;j<G[i].size();j++){
  32.             int u = G[i][j].second;
  33.             if (dp[u].first>max(dp[i-1].first,G[i][j].first.first)){
  34.                 dp[u] = make_pair(max(dp[i-1].first,G[i][j].first.first),dp[i-1].second+G[i][j].first.second);
  35.             }
  36.             else if (dp[u].first==max(dp[i-1].first , G[i][j].first.first)){
  37.                 dp[u].second = min(dp[u].second,dp[i-1].second+G[i][j].first.second);
  38.             }
  39.         }
  40.     }
  41.     cout<<dp[m].first<<" "<<dp[m].second;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment