이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#include "stations.h"
//#include "stub.cpp"
#include <vector>
#define pb push_back
vector<int> adj[1005];
set<int> ss;
map<int,int> mp;
int st[1005],ed[1005],tim=0,lv[1005],pack[1005],cnt;
void dfs(int u,int p)
{
st[u]=++tim;
for(auto node:adj[u])
{
if(node==p)continue;
lv[node]=1-lv[u];
dfs(node,u);
}
ed[u]=++tim;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i=1;i<=n;i++)adj[i].clear();
for (int i = 0; i < n-1; i++)
{
adj[u[i]+1].pb(v[i]+1);
adj[v[i]+1].pb(u[i]+1);
}
lv[1]=0;
dfs(1,1);
for(int i=1;i<=n;i++)
{
if(lv[i]==0)
{
pack[i]=st[i];
}else
{
pack[i]=ed[i];
}
}
for(int i=1;i<=n;i++)ss.insert(pack[i]);
cnt=0;
for(auto it=ss.begin();it!=ss.end();it++)
{
mp[(*it)]=cnt;
++cnt;
}
for(int i=1;i<=n;i++)pack[i]=mp[pack[i]];
labels.clear();
for(int i=0;i<n;i++)labels.pb(pack[i+1]);
/*for(int i=1;i<=n;i++)
{
printf("%d\n",i);
for(auto node:adj[i])
{
printf("%d ",node);
}
printf("\n");
}*/
/*for(int i=0;i<labels.size();i++)
{
printf("%d ",labels[i]);
}
printf("\n");*/
return labels;
}
int find_next_station(int s, int t, std::vector<int> c)
{
//printf("hk\n");
//printf("s=%d t=%d\n",s,t);
//printf("adj\n");
/*for(auto node:c)
{
printf("%d ",node);
}
printf("\n");*/
if(c.size()==1)return c[0];
sort(c.begin(),c.end());
if(s>c[0])
{
for(int i=1;i<c.size()-1;i++)
{
if(t>=c[i]&&t<c[i+1])
{
return c[i];
}
}
if(t>=c[c.size()-1]&&t<s)return c[c.size()-1];
return c[0];
}else
{
if(t<c[0]&&t>s)return c[0];
for(int i=1;i<c.size()-1;i++)
{
if(t>c[i-1]&&t<c[i])
{
return c[i];
}
}
return c[c.size()-1];
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=1;i<c.size()-1;i++)
| ~^~~~~~~~~~~
stations.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i=1;i<c.size()-1;i++)
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |