답안 #422613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422613 2021-06-10T09:10:43 Z TLP39 기지국 (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> adj[1003];
int par[1003]={};
int si[1003]={};
int lab[1003];

void dfs(int v)
{
    si[v]=1;
    for(int i=0;i<adj[v].size();i++)
    {
        if(adj[v][i]==par[v]) continue;
        par[adj[v][i]]=v;
        dfs(adj[v][i]);
        si[v]+=si[adj[v][i]];
    }
}

void getlabel(int v,int st,int ed)
{
    lab[v]=st;
    if(st==ed) return;
    int x=st,y;
    if(st<ed)
    {
        for(int i=0;i<adj[v].size();i++)
        {
            if(adj[v][i]==par[v]) continue;
            y=x+1;
            x+=si[adj[v][i]];
            getlabel(adj[v][i],x,y);
        }
        return;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        if(adj[v][i]==par[v]) continue;
        y=x-1;
        x-=si[adj[v][i]];
        getlabel(adj[v][i],x,y);
    }
    return;
}

std::vector<int> label(int N, int k, std::vector<int> u, std::vector<int> v) {
    n=N;
	std::vector<int> labels(N);
	par[0]=-1;
	for(int i=0;i<n-1;i++)
	{
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}
	dfs(0);
	getlabel(0,0,n-1);
	for(int i=0;i<n;i++) labels[i]=lab[i];
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size()==1) return c[0];
	if(s==0)
	{
        for(int i=0;i<c.size();i++)
        {
            if(c[i]>=t) return c[i];
        }
	}
	if(c[0]<s)
	{
        if(t>s || t<c[1]) return c[0];
        for(int i=c.size()-1;i>0;i--)
        {
            if(c[i]<=t) return c[i];
        }
	}
	int ss=c.size()-1;
	if(t<s || t>c[ss-1]) return c[ss];
	for(int i=0;i<ss;i++)
	{
        if(t<=c[i]) return c[i];
	}
	return -1;
}

Compilation message

stations.cpp: In function 'void dfs(int)':
stations.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<adj[v].size();i++)
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'void getlabel(int, int, int)':
stations.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i=0;i<adj[v].size();i++)
      |                     ~^~~~~~~~~~~~~~
stations.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<adj[v].size();i++)
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int i=0;i<c.size();i++)
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2492 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3041 ms 420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1672 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 922 ms 552 KB Output is correct
2 Runtime error 1320 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2857 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -