답안 #321836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321836 2020-11-13T12:35:37 Z lukameladze 기지국 (IOI20_stations) C++14
100 / 100
1063 ms 15500 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;
  v2.clear();
	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:51: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]
   51 |     for (int i=0; i<v2.size(); i++)
      |                   ~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int i=1; i<c.size()-1; i++)
      |                       ~^~~~~~~~~~~
stations.cpp:77:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (int i=1; i<c.size()-1; i++)
      |                       ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 14944 KB Output is correct
2 Correct 465 ms 15116 KB Output is correct
3 Correct 974 ms 14976 KB Output is correct
4 Correct 735 ms 14816 KB Output is correct
5 Correct 653 ms 15016 KB Output is correct
6 Correct 455 ms 15132 KB Output is correct
7 Correct 457 ms 15328 KB Output is correct
8 Correct 11 ms 14816 KB Output is correct
9 Correct 13 ms 14872 KB Output is correct
10 Correct 11 ms 14816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 15140 KB Output is correct
2 Correct 585 ms 15324 KB Output is correct
3 Correct 943 ms 15016 KB Output is correct
4 Correct 735 ms 15008 KB Output is correct
5 Correct 690 ms 15016 KB Output is correct
6 Correct 509 ms 15024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 15120 KB Output is correct
2 Correct 468 ms 15092 KB Output is correct
3 Correct 1004 ms 14816 KB Output is correct
4 Correct 763 ms 14816 KB Output is correct
5 Correct 594 ms 14944 KB Output is correct
6 Correct 502 ms 15120 KB Output is correct
7 Correct 506 ms 15256 KB Output is correct
8 Correct 11 ms 15024 KB Output is correct
9 Correct 13 ms 14944 KB Output is correct
10 Correct 10 ms 15016 KB Output is correct
11 Correct 672 ms 14816 KB Output is correct
12 Correct 607 ms 15244 KB Output is correct
13 Correct 590 ms 15072 KB Output is correct
14 Correct 448 ms 14944 KB Output is correct
15 Correct 62 ms 15012 KB Output is correct
16 Correct 81 ms 15072 KB Output is correct
17 Correct 143 ms 15140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1063 ms 14816 KB Output is correct
2 Correct 699 ms 15016 KB Output is correct
3 Correct 635 ms 14816 KB Output is correct
4 Correct 11 ms 15016 KB Output is correct
5 Correct 13 ms 15016 KB Output is correct
6 Correct 10 ms 14816 KB Output is correct
7 Correct 591 ms 14944 KB Output is correct
8 Correct 986 ms 14944 KB Output is correct
9 Correct 749 ms 15188 KB Output is correct
10 Correct 580 ms 15176 KB Output is correct
11 Correct 13 ms 15016 KB Output is correct
12 Correct 13 ms 14816 KB Output is correct
13 Correct 14 ms 14944 KB Output is correct
14 Correct 12 ms 14944 KB Output is correct
15 Correct 11 ms 14816 KB Output is correct
16 Correct 540 ms 14944 KB Output is correct
17 Correct 511 ms 14944 KB Output is correct
18 Correct 508 ms 15016 KB Output is correct
19 Correct 466 ms 14944 KB Output is correct
20 Correct 491 ms 14944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 15112 KB Output is correct
2 Correct 487 ms 15072 KB Output is correct
3 Correct 830 ms 15016 KB Output is correct
4 Correct 651 ms 15024 KB Output is correct
5 Correct 593 ms 15072 KB Output is correct
6 Correct 425 ms 14944 KB Output is correct
7 Correct 434 ms 15072 KB Output is correct
8 Correct 11 ms 15024 KB Output is correct
9 Correct 12 ms 14944 KB Output is correct
10 Correct 10 ms 14816 KB Output is correct
11 Correct 464 ms 14944 KB Output is correct
12 Correct 491 ms 15280 KB Output is correct
13 Correct 868 ms 15016 KB Output is correct
14 Correct 657 ms 15188 KB Output is correct
15 Correct 631 ms 15016 KB Output is correct
16 Correct 477 ms 15072 KB Output is correct
17 Correct 625 ms 15104 KB Output is correct
18 Correct 448 ms 15200 KB Output is correct
19 Correct 469 ms 15104 KB Output is correct
20 Correct 443 ms 15160 KB Output is correct
21 Correct 71 ms 15012 KB Output is correct
22 Correct 77 ms 14944 KB Output is correct
23 Correct 125 ms 15140 KB Output is correct
24 Correct 13 ms 14944 KB Output is correct
25 Correct 15 ms 14816 KB Output is correct
26 Correct 13 ms 14816 KB Output is correct
27 Correct 13 ms 14816 KB Output is correct
28 Correct 10 ms 15016 KB Output is correct
29 Correct 582 ms 15072 KB Output is correct
30 Correct 596 ms 15196 KB Output is correct
31 Correct 471 ms 15024 KB Output is correct
32 Correct 500 ms 15196 KB Output is correct
33 Correct 497 ms 15104 KB Output is correct
34 Correct 338 ms 15248 KB Output is correct
35 Correct 415 ms 15072 KB Output is correct
36 Correct 426 ms 15176 KB Output is correct
37 Correct 470 ms 14944 KB Output is correct
38 Correct 452 ms 15084 KB Output is correct
39 Correct 425 ms 15092 KB Output is correct
40 Correct 447 ms 15500 KB Output is correct
41 Correct 502 ms 15224 KB Output is correct
42 Correct 72 ms 15092 KB Output is correct
43 Correct 106 ms 15200 KB Output is correct
44 Correct 142 ms 15072 KB Output is correct
45 Correct 160 ms 15088 KB Output is correct
46 Correct 322 ms 15168 KB Output is correct
47 Correct 323 ms 15124 KB Output is correct
48 Correct 86 ms 15072 KB Output is correct
49 Correct 73 ms 15200 KB Output is correct