Submission #800172

#TimeUsernameProblemLanguageResultExecution timeMemory
800172AndreyDreaming (IOI13_dreaming)C++14
0 / 100
34 ms12816 KiB
#include "dreaming.h" #include<bits/stdc++.h> using namespace std; int n,m; vector<pair<int,int>> haha[100001]; vector<int> dp(100001,-1); int dude(int a, int t, int d) { int ans = max(dp[a],d),big = 0,big2 = 0,b,c,e; for(int i = 0; i < haha[a].size(); i++) { if(haha[a][i].first != t) { b = haha[a][i].first; c = haha[a][i].second; if(dp[b]+c > big) { big2 = big; big = dp[b]+c; } else if(dp[b]+c > big2) { big2 = dp[b]+c; } } } for(int i = 0; i < haha[a].size(); i++) { if(haha[a][i].first != t) { b = haha[a][i].first; c = haha[a][i].second; if(c+dp[b] == big) { e = max(d,big2)+c; } else { e = max(d,big)+c; } ans = min(ans,dude(b,a,e)); } } return ans; } void dfs(int a, int t) { dp[a] = 0; for(int i = 0; i < haha[a].size(); i++) { if(haha[a][i].first != t) { dfs(haha[a][i].first,a); dp[a] = max(dp[a],dp[haha[a][i].first]+haha[a][i].second); } } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n = N; m = M; for(int i = 0; i < m; i++) { haha[A[i]].push_back({B[i],T[i]}); haha[B[i]].push_back({A[i],T[i]}); } vector<int> wut(0); for(int i = 0; i < n; i++) { if(dp[i] == -1) { dfs(i,-1); wut.push_back(i); } } vector<int> wow(0); for(int i = 0; i < wut.size(); i++) { wow.push_back(dude(wut[i],-1,0)); } sort(wow.begin(),wow.end()); if(wow.size() == 1) { return wow[0]; } else if(wow.size() == 2) { return wow[0]+wow[1]+L; } else { return max(wow[wow.size()-1]+wow[wow.size()-2]+L,wow[wow.size()-2]+wow[wow.size()-2]+2*L); } }

Compilation message (stderr)

dreaming.cpp: In function 'int dude(int, int, int)':
dreaming.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
dreaming.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i = 0; i < wut.size(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...