답안 #321834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321834 2020-11-13T12:30:29 Z lukameladze 기지국 (IOI20_stations) C++14
0 / 100
1004 ms 15200 KB
#include "stations.h"
# include <bits/stdc++.h>
using namespace std;
long long lv[300005],tin,out[300005],in[300005],x[300005],tout;
std::vector <long long> v1[300005];
std::vector <int> labels;
 
vector < pair <long long, long long> >v2;
void dfs(int a, int p)
{
	if (p!=-1)
    lv[a]=lv[p]+1;
    else lv[a]=1;
    tin++;
    in[a]=tin;
    for (int i=0; i<v1[a].size(); i++)
    {
        if (p!=v1[a][i])
        {
            dfs(v1[a][i],a);
        }
    }
    tin++;
    out[a]=tin;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) 
{
	labels.clear();
	labels.resize(n);
	for (int i=0; i<n; i++)
	v1[i].clear(), lv[i]=0;
	tin=0;
    for (int i=0; i<n-1; i++)
    {
        v1[u[i]].push_back(v[i]);
        v1[v[i]].push_back(u[i]);
    }
   
    dfs(0,-1);
    for (int i=0; i<n; i++)
    {
        if (lv[i]%2==1)
        {
            x[i]=in[i];
        }
        else x[i]=out[i];
        v2.push_back({x[i],i});
    }
    sort(v2.begin(), v2.end());
    for (int i=0; i<v2.size(); i++)
    { 
        labels[v2[i].second]=i;
    }
    return labels;
}
int find_next_station(int s, int t, std::vector<int> c) 
{
    if (c[0]<s)
    {
        for (int i=1; i<c.size()-1; i++)
        {
            tin=c[i];
            tout=c[i+1]-1;
            if (tin>=t && tout<=t) return c[i];
        }
        tin=c[c.size()-1];
        tout=s-1;
        if (tin>=t && tout<=t) return c[c.size()-1];
        return c[0];
    }
    else
    {
        tin=s+1;
        tout=c[0];
        if (tin>=t && tout<=t) return c[0];
        for (int i=1; i<c.size()-1; i++)
        {
            tin=c[i-1]+1;
            tout=c[i];
            if (tin>=t && tout<=t) return c[i];
        }
        return c[c.size()-1];
    }
}

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<v1[a].size(); i++)
      |                   ~^~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i=0; i<v2.size(); i++)
      |                   ~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for (int i=1; i<c.size()-1; i++)
      |                       ~^~~~~~~~~~~
stations.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int i=1; i<c.size()-1; i++)
      |                       ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 7788 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1008
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 7908 KB Invalid labels (values out of range). scenario=1, k=1000, vertex=1, label=1023
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 547 ms 15200 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1004 ms 15024 KB Output is correct
2 Incorrect 718 ms 15016 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 681 ms 15200 KB Wrong query response.
2 Halted 0 ms 0 KB -