#include <iostream>
#include <algorithm>
#include <vector>
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
vector<int> con[1001];
vector<int> son[1001];
bool used[1001];
vector<int> ans;
void rt(int x)
{
int i;
for(i=0;i<con[x].size();i++){
int f=con[x][i];
if(!used[f])
son[x].pb(f), used[f]=true, rt(f);
}
}
pii wk(int x, int lev, int label)
{
pii ret={label, 1};
int i;
if(lev%2==0){
ans[x]=label;
for(i=0;i<son[x].size();i++){
pii f=wk(son[x][i], lev+1, label+1);
label+=f.second;
ret.first=max(ret.first, f.first);
ret.second+=f.second;
}
}
if(lev%2==1){
for(i=0;i<son[x].size();i++){
pii f=wk(son[x][i], lev+1, label);
label+=f.second;
ret.first=max(ret.first, f.first);
ret.second+=f.second;
}
ans[x]=label;
}
return ret;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
int i;
for(i=0;i<=1000;i++){
con[i].clear();
son[i].clear();
used[i]=false;
}
ans.clear();
for(i=0;i<n;i++){
con[u[i]].pb(v[i]);
con[v[i]].pb(u[i]);
ans.pb(0);
}
rt(0);
wk(0, 1, 1);
return ans;
}
int find_next_station(int s, int t, vector<int> nei)
{
int lev=1;
int i;
for(i=0;i<nei.size();i++)
if(nei[i]<s)
lev=0;
if(lev==1){
sort(nei.begin(), nei.end());
bool maxi=false;
if(t<s)
maxi=true;
if(maxi)
return nei[nei.size()-1];
for(i=int(nei.size())-1;i>=0;i--)
if(t>nei[i])
return nei[i];
}
else{
sort(nei.begin(), nei.end());
bool mini=false;
if(t>=nei[nei.size()-1])
mini=true;
if(mini)
return nei[0];
for(i=0;i<nei.size();i++)
if(t<nei[i])
return nei[i];
}
return -1;
}
Compilation message
stations.cpp: In function 'void rt(int)':
stations.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(i=0;i<con[x].size();i++){
| ~^~~~~~~~~~~~~~
stations.cpp: In function 'pii wk(int, int, int)':
stations.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(i=0;i<son[x].size();i++){
| ~^~~~~~~~~~~~~~
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(i=0;i<son[x].size();i++){
| ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:81:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(i=0;i<nei.size();i++)
| ~^~~~~~~~~~~
stations.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(i=0;i<nei.size();i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1340 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1249 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1248 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1237 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1228 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |