Submission #942402

#TimeUsernameProblemLanguageResultExecution timeMemory
942402emad234Dreaming (IOI13_dreaming)C++17
100 / 100
70 ms31836 KiB
#include <bits/stdc++.h> #include "dreaming.h" #define ll long long #define F first #define S second #define pii pair<int,int> const int mod = 1e9 + 7; const int mxN = 2e5 + 5; using namespace std; vector<vector<pii>>v; vector<int>nums; int mx[mxN]; bool vis[mxN]; int ans = 0; int path; int dpD[mxN],dpU[mxN]; void dfs(int u){ vis[u] = 1; for(auto x : v[u]){ if(vis[x.F]) continue; dfs(x.F); dpD[u] = max(dpD[x.F] + x.S,dpD[u]); } } void hfs(int u,int par){ multiset<int>s; for(auto x : v[u]){ if(x.F == par) continue; s.insert(dpD[x.F] + x.S); } for(auto x : v[u]){ if(x.F == par) continue; dpU[x.F] = dpU[u] + x.S; s.erase(s.find(dpD[x.F] + x.S)); if(s.size()) dpU[x.F] = max(dpU[x.F], *(s.rbegin()) + x.S); s.insert(dpD[x.F] + x.S); } for(auto x : v[u]) if(x.F != par) hfs(x.F,u); path = min(path,max(dpD[u],dpU[u])); ans = max({ans,dpU[u],dpD[u]}); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { v.clear(); v.resize(N + 2); for(int i = 0;i < M;i++){ v[A[i]].push_back({B[i],T[i]}); v[B[i]].push_back({A[i],T[i]}); } for(int i = 0;i < N;i++){ if(!vis[i]){ path = 2e9; dfs(i); hfs(i,-1); nums.push_back(path + L); } } sort(nums.begin(),nums.end()); nums[nums.size() - 1] -= L; sort(nums.begin(),nums.end()); // for(auto x : nums) cout<<x<<' '; // cout<<'\n'; for(int i = 0;i < nums.size();i++){ int num = 0; if(i == nums.size() - 1){ if(i != 0){ num = nums[i] + nums[i - 1]; } } else num = nums[i] + nums[nums.size() - 1]; ans = max(num,ans); } return ans; } // #define MAX_N 100000 // static int A[MAX_N]; // static int B[MAX_N]; // static int T[MAX_N]; // int main() { // int N, M, L, i; // int res; // cin >>N>>M>>L; // for (i = 0; i < M; i++) // cin>>A[i]>>B[i]>>T[i]; // int answer = travelTime(N, M, L, A, B, T); // printf("%d\n", answer); // return 0; // }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0;i < nums.size();i++){
      |                   ~~^~~~~~~~~~~~~
dreaming.cpp:64:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         if(i == nums.size() - 1){
      |            ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...