Submission #831462

#TimeUsernameProblemLanguageResultExecution timeMemory
831462TrumlingStations (IOI20_stations)C++14
0 / 100
1 ms296 KiB
#include "stations.h" #include <vector> #include<bits/stdc++.h> using namespace std; #define F first #define S second #define all(x) x.begin(),x.end() typedef long long ll; #define pb push_back #define INF 99999999999 ll nn; vector<vector<int>>g; ll here=0; vector<int>labels; void dfs(int i,int id,int start,int pre) { labels[start]=i*nn + id; //cout<<labels[start]<<' '; for(auto x:g[start]) if(pre!=x) dfs(i,id+1,x,start); return ; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { nn=n; g.assign(n,vector<int>()); labels.assign(n,0); vector<bool>cnt(n,0); for (int i = 0; i < n-1; i++) { g[u[i]].pb(v[i]); g[v[i]].pb(u[i]); if(g[u[i]].size()>2) here=u[i]; if(g[v[i]].size()>2) here=v[i]; if(g[u[i]].size()==2) cnt[u[i]]=1; if(g[v[i]].size()==2) cnt[v[i]]=1; } if(g[here].size()<=2) for(int i=0;i<n;i++) if(!cnt[i]) { here=i; break; } //cout<<here<<'\n'; for(int i=0;i<g[here].size();i++) dfs(i,1,g[here][i],here); for(int i=0;i<n;i++) cout<<labels[i]<<' '; return labels; } int find_next_station(int s, int t, vector<int> c) { if(c.size()>2) { ll j=0; ll l=0,r=nn; while(l<r) { ll mid=(l+r)/2; if(t-mid*nn>0) l=mid+1; else r=mid; } return (l-1)*nn+1; } int mini=INF; for(auto x:c) mini=min(x,mini); if(t<s) return mini; ll l=0,r=nn; while(l<r) { ll mid=(l+r)/2; if(t-mid*nn>0) l=mid+1; else r=mid; } ll j=l-1; l=0,r=nn; while(l<r) { ll mid=(l+r)/2; if(s-mid*nn>0) l=mid+1; else r=mid; } ll i=l-1; if(i==j) return s+1; else return mini; } /* 1 6 10000 0 1 1 2 2 3 1 4 4 5 */

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:65:16: 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<g[here].size();i++)
      |               ~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:78:7: warning: unused variable 'j' [-Wunused-variable]
   78 |    ll j=0;
      |       ^
stations.cpp:11:17: warning: overflow in conversion from 'long int' to 'int' changes value from '99999999999' to '1215752191' [-Woverflow]
   11 |     #define INF 99999999999
      |                 ^~~~~~~~~~~
stations.cpp:91:12: note: in expansion of macro 'INF'
   91 |   int mini=INF;
      |            ^~~
#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...