Submission #432749

#TimeUsernameProblemLanguageResultExecution timeMemory
432749charterlaStations (IOI20_stations)C++14
5 / 100
867 ms780 KiB
#include "stations.h" #include <iostream> #include <algorithm> #include <vector> using namespace std; struct Node{ vector<int> to; int deg; }point[1005]; vector<int> labels; int num; void build(int now,int last,int p){ //cout<<now<<"<-"<<last<<":"<<p<<endl; if(p%2==0)labels[now]=num++; for(int i=0;i<point[now].to.size();i++){ int next=point[now].to[i]; if(next!=last)build(next,now,p+1); } if(p%2==1)labels[now]=num++; } 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; } 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,-1,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];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-1: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]; } } } /* 1 5 10 0 1 1 2 1 3 2 4 */

Compilation message (stderr)

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