Submission #897402

#TimeUsernameProblemLanguageResultExecution timeMemory
897402Muhammad_Aneeq꿈 (IOI13_dreaming)C++17
14 / 100
1056 ms13864 KiB
#include <vector> #include <algorithm> #include "dreaming.h" using namespace std; int const N=1e5+10; vector<pair<int,int>>nei[N]={}; vector<int>heads; bool vis[N]={}; int cost[N]={}; void dfs(int n) { vis[n]=1; for (auto [i,w]:nei[n]) { if (!vis[i]) { cost[n]+=w; dfs(i); cost[n]+=cost[i]; } } } vector<pair<int,int>>cur={}; bool w=0; void getroot(int n,int pa,int root) { int f=cost[root]-cost[n]; for (auto [i,w]:nei[n]) { if (i!=pa) { f=max(f,cost[i]+w); getroot(i,n,root); } else f=max(f,cost[root]-cost[n]); } cur.push_back({f,n}); } int travelTime(int n, int m, int l, int a[], int b[], int t[]) { for (int i=0;i<m;i++) { nei[a[i]].push_back({b[i],t[i]}); nei[b[i]].push_back({a[i],t[i]}); } for (int i=0;i<n;i++) { if (!vis[i]) { heads.push_back(i); dfs(i); } } for (int i=0;i<n;i++) vis[i]={}; vector<pair<int,int>>new_head; for (auto i:heads) { if (i!=heads[0]) w=1; getroot(i,-1,i); sort(begin(cur),end(cur)); new_head.push_back(cur[0]); cur={}; } sort(begin(new_head),end(new_head)); reverse(begin(new_head),end(new_head)); for (int i=1;i<new_head.size();i++) { nei[new_head[0].second].push_back({new_head[i].second,l}); nei[new_head[i].second].push_back({new_head[0].second,l}); } int ans=new_head[0].first+new_head[1].first+l; for (int i=1;i<new_head.size();i++) { for (int j=i+1;j<new_head.size();j++) ans=max(ans,new_head[i].first+new_head[j].first+l+l); } for (auto i:heads) ans=max(ans,cost[i]); return ans; }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for (int i=1;i<new_head.size();i++)
      |               ~^~~~~~~~~~~~~~~~
dreaming.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for (int i=1;i<new_head.size();i++)
      |               ~^~~~~~~~~~~~~~~~
dreaming.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for (int j=i+1;j<new_head.size();j++)
      |                  ~^~~~~~~~~~~~~~~~
#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...