# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1234313 | caacrugon | 기지국 (IOI20_stations) | C++20 | 0 ms | 0 KiB |
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = i;
}
vector<int> indegree(n,0);
vector<vector<int>> adj(n,vector<int>(0,0));
for(int i=0;i<n;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
indegree[u[i]]++;
indegree[v[i]]++;
}
queue<int> q;
for(int i=0;i<n;i++){
if(indegree[i]==1){
q.push(i);
break;
}
}
int i=0;
vector<bool> visited(n,false);
while(q.size()){
int nodo=q.front();
q.pop();
labels[nodo]=i;
visited[nodo]=true;
i++;
for(int j=0;j<adj[nodo].size();j++){
if(visited[adj[nodo][j]])continue;
q.push(adj[nodo][j]);
}
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size==2){
if(c[0]%2==0 && c[1]%2==0 && s%2==0){
if(t%2==0 && t>s){
return c[1];
}
return c[0]
}else if(c[0]%2!=0 && c[1]%2!=0 && s%2!=0){
if(t%2!=0 && t>s){
return c[1];
}
return c[0]
}else if(s%2==0 && c[1]%2==0){
if(t%2==0 && t>s){
return c[1];
}
return c[0];
}else if(s%2!=0 && c[1]%2!=0){
if(t%2!=0 && t>s){
return c[1];
}
return c[0];
}else{
if(t>s)return c[1];
return c[0]
}
}else if(c.size()==3){
if(t>s && t%2==0){
for(int i=1;i<=2;i++)if(c[i]%2==0)return c[i];
}else if(t>s && t%2!=0){
for(int i=1;i<=2;i++)if(c[i]%2!=0)return c[i];
}
return c[0];
}else return c[0];
}