Submission #1109845

#TimeUsernameProblemLanguageResultExecution timeMemory
1109845SonicMLDreaming (IOI13_dreaming)C++14
18 / 100
37 ms13136 KiB
#include "dreaming.h" #include <vector> #include <iostream> using namespace std; struct Edge{ int to; int cost; }; int const NMAX = 1e5; vector <Edge> g[1 + NMAX]; int below[1 + NMAX]; int above[1 + NMAX]; int visit[1 + NMAX]; void computeBelow(int node, int parent) { visit[node] = true; for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { computeBelow(to, node); below[node] = max(below[node], below[to] + cost); } } } int computeAbove(int node, int parent) { int ans = max(above[node], below[node]); //cerr << node << ' ' << above[node] << ' ' << below[node] << '\n'; visit[node] = true; int best1 = above[node], best2 = 0; for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { if(best1 < below[to] + cost) { best2 = best1; best1 = below[to] + cost; }else if(best2 < below[to] + cost) { best2 = below[to] + cost; } } } for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { if(below[to] + cost == best1) { above[to] = best2 + cost; }else { above[to] = best1 + cost; } ans = min(ans, computeAbove(to, node)); } } return ans; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(int i = 0;i < M;i++) { g[A[i]].push_back({B[i], T[i]}); g[B[i]].push_back({A[i], T[i]}); } for(int i = 0;i < N;i++) { if(!visit[i]) { computeBelow(i, i); } } for(int i = 0;i < N;i++) { visit[i] = 0; } vector <int> len; int core = 0; for(int i = 0;i < N;i++) { if(!visit[i]) { int temp = computeAbove(i, i); //cerr << temp << '\n'; len.push_back(temp); if(len[core] < temp) { core = len.size()-1; } } } //cerr << '\n'; int best1 = 0, best2 = 0; for(int i = 0;i < len.size();i++) { int temp; if(i == core) { temp = len[i]; }else { temp = len[i] + L; } if(best1 < temp) { best2 = best1; best1 = temp; }else if(best2 < temp) { best2 = temp; } } return best1 + best2; }

Compilation message (stderr)

dreaming.cpp: In function 'void computeBelow(int, int)':
dreaming.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int i = 0;i < g[node].size();i++) {
      |                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int computeAbove(int, int)':
dreaming.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0;i < g[node].size();i++) {
      |                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for(int i = 0;i < g[node].size();i++) {
      |                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:87:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i = 0;i < len.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...