Submission #431670

#TimeUsernameProblemLanguageResultExecution timeMemory
431670charterlaStations (IOI20_stations)C++14
0 / 100
2414 ms2097156 KiB
#include "stations.h" #include <iostream> #include <algorithm> #include <vector> using namespace std; struct Node{ vector<int> to; int deg,in,out; }point[1005]; vector<int> labels; int num; int build(int now,int p){ point[now].in=point[now].out=num++; for(int i=0;i<point[now].to.size();i++){ int next=point[now].to[i]; point[now].out=max(point[now].out,build(next,p+1)); } if(p%2==0)labels[now]=point[now].in; else labels[now]=point[now].out; return point[now].out; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { num=0; labels.clear();labels.resize(n); for(int i=0;i<n;i++){ point[i].to.clear(); point[i].deg=0; point[i].in=-1; point[i].out=-1; } int root=0; for(int i=0;i<n-1;i++){ point[u[i]].to.push_back(v[i]); point[u[i]].deg++; if(point[u[i]].deg>point[root].deg)root=u[i]; point[v[i]].to.push_back(u[i]); point[v[i]].deg++; if(point[v[i]].deg>point[root].deg)root=v[i]; } build(root,0); //for(int i=0;i<n;i++)cout<<labels[i]<<" ";cout<<endl; return labels; } int find_next_station(int s, int t, vector<int> c){ if(c.size()==1)return c[0]; bool way=true; for(int i=0;i<c.size();i++){ if(s<c[i]){ way=false; break; } } int ls=-1,rs=-1; if(way){ sort(c.begin(),c.end()); ls=c[1]-1;rs=s; if(t<ls || t>rs)return c[0]; for(int i=1;i<c.size();i++){ ls=c[i];rs=(i==c.size()-1?s:c[i+1]-1); if(ls<=t && t<=rs)return c[i]; } } else{ sort(c.rbegin(),c.rend()); ls=s;rs=c[1]; if(t<ls || t>rs)return c[0]; for(int i=1;i<c.size();i++){ ls=(i==1?s+1:c[i-1]+1);rs=c[i]; if(ls<=t && t<=rs)return c[i]; } } }

Compilation message (stderr)

stations.cpp: In function 'int build(int, int)':
stations.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i=0;i<point[now].to.size();i++){
      |              ~^~~~~~~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i=0;i<c.size();i++){
      |              ~^~~~~~~~~
stations.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=1;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |    ls=c[i];rs=(i==c.size()-1?s:c[i+1]-1);
      |                ~^~~~~~~~~~~~
stations.cpp:82:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |   for(int i=1;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
   87 | }
      | ^
#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...