답안 #436410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436410 2021-06-24T13:24:41 Z 20160161simone 기지국 (IOI20_stations) C++14
100 / 100
1253 ms 872 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e3+10;
struct edge{
	ll to,nxt;
}ln[N*2];
ll idx[N],topln;
void add_edge(ll u,ll v){
	ln[++topln]=(edge){v,idx[u]},idx[u]=topln;
	ln[++topln]=(edge){u,idx[v]},idx[v]=topln;
}
ll dep[N],dfn[N],siz[N];
void dfs0(ll x,ll fa){
	siz[x]=1;
	for(ll i=idx[x];i;i=ln[i].nxt){
		if(ln[i].to==fa) continue;
		dfs0(ln[i].to,x);
		siz[x]+=siz[ln[i].to];
	}
}
void dfs(ll x,ll fa,ll l,ll r){
	if(dep[x]%2==0) dfn[x]=l; 
	else dfn[x]=r;
	ll t=dfn[x];
	// printf(":: %lld %lld %lld\n",x,l,r);
	for(ll i=idx[x];i;i=ln[i].nxt){
		if(ln[i].to==fa) continue;
		dep[ln[i].to]=dep[x]+1;
		if(dep[x]%2==0){
			dfs(ln[i].to,x,t+1,t+siz[ln[i].to]);
			t+=siz[ln[i].to];
		}
		else{
			dfs(ln[i].to,x,t-siz[ln[i].to],t-1);
			t-=siz[ln[i].to];
		}
	}
}
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	memset(dep,0,sizeof(dep));
	memset(dfn,0,sizeof(dfn));
	memset(idx,0,sizeof(idx));
	topln=0;
	for(ll i=0;i<u.size();i++) add_edge(u[i],v[i]);
	dfs0(0,0);
	dfs(0,0,1,n);
	vector<int> lab;
	for(ll i=0;i<n;i++) lab.push_back(dfn[i]);
	// for(ll i=0;i<n;i++) printf("%lld ",siz[i]);cout<<endl;
	return lab;
}
 
int find_next_station(int s, int t, vector<int> c) {
	for(ll i=0;i<c.size();i++){
		if(t==c[i]) return c[i];
	}
	// for(ll i=0;i<c.size();i++) printf("%lld ",c[i]);cout<<endl;
	if(s<c[0]){
		for(ll i=0;i<c.size()-1;i++){
			if(s<t && t<c[i]) return c[i];
		}
		return c[c.size()-1];
	}
	else{//c[0]<s
		for(ll i=c.size()-1;i>0;i--){
			if(c[i]<t && t<s) return c[i];
		}
		return c[0];
	}
	//printf("%lld %lld\n",s,t);
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:47:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(ll i=0;i<u.size();i++) add_edge(u[i],v[i]);
      |             ~^~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(ll i=0;i<c.size();i++){
      |             ~^~~~~~~~~
stations.cpp:62:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(ll i=0;i<c.size()-1;i++){
      |              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 731 ms 612 KB Output is correct
2 Correct 559 ms 528 KB Output is correct
3 Correct 1253 ms 400 KB Output is correct
4 Correct 873 ms 484 KB Output is correct
5 Correct 936 ms 476 KB Output is correct
6 Correct 789 ms 528 KB Output is correct
7 Correct 506 ms 556 KB Output is correct
8 Correct 4 ms 456 KB Output is correct
9 Correct 5 ms 420 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 488 KB Output is correct
2 Correct 784 ms 584 KB Output is correct
3 Correct 958 ms 400 KB Output is correct
4 Correct 1126 ms 400 KB Output is correct
5 Correct 698 ms 484 KB Output is correct
6 Correct 553 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 597 ms 608 KB Output is correct
2 Correct 550 ms 608 KB Output is correct
3 Correct 1206 ms 400 KB Output is correct
4 Correct 851 ms 468 KB Output is correct
5 Correct 721 ms 400 KB Output is correct
6 Correct 619 ms 620 KB Output is correct
7 Correct 512 ms 604 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 6 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 794 ms 484 KB Output is correct
12 Correct 707 ms 620 KB Output is correct
13 Correct 620 ms 616 KB Output is correct
14 Correct 468 ms 488 KB Output is correct
15 Correct 51 ms 528 KB Output is correct
16 Correct 80 ms 528 KB Output is correct
17 Correct 182 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1077 ms 400 KB Output is correct
2 Correct 872 ms 400 KB Output is correct
3 Correct 803 ms 480 KB Output is correct
4 Correct 3 ms 476 KB Output is correct
5 Correct 6 ms 600 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 749 ms 480 KB Output is correct
8 Correct 1049 ms 476 KB Output is correct
9 Correct 1004 ms 400 KB Output is correct
10 Correct 864 ms 484 KB Output is correct
11 Correct 9 ms 716 KB Output is correct
12 Correct 9 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 7 ms 792 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 646 ms 472 KB Output is correct
17 Correct 846 ms 540 KB Output is correct
18 Correct 563 ms 488 KB Output is correct
19 Correct 670 ms 400 KB Output is correct
20 Correct 610 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 693 ms 596 KB Output is correct
2 Correct 768 ms 872 KB Output is correct
3 Correct 1101 ms 476 KB Output is correct
4 Correct 969 ms 464 KB Output is correct
5 Correct 647 ms 460 KB Output is correct
6 Correct 507 ms 528 KB Output is correct
7 Correct 558 ms 592 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 7 ms 788 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 716 ms 488 KB Output is correct
12 Correct 569 ms 648 KB Output is correct
13 Correct 997 ms 484 KB Output is correct
14 Correct 890 ms 492 KB Output is correct
15 Correct 861 ms 400 KB Output is correct
16 Correct 762 ms 528 KB Output is correct
17 Correct 961 ms 484 KB Output is correct
18 Correct 583 ms 684 KB Output is correct
19 Correct 596 ms 680 KB Output is correct
20 Correct 583 ms 480 KB Output is correct
21 Correct 62 ms 548 KB Output is correct
22 Correct 107 ms 528 KB Output is correct
23 Correct 158 ms 528 KB Output is correct
24 Correct 7 ms 468 KB Output is correct
25 Correct 7 ms 468 KB Output is correct
26 Correct 8 ms 604 KB Output is correct
27 Correct 6 ms 600 KB Output is correct
28 Correct 2 ms 476 KB Output is correct
29 Correct 615 ms 484 KB Output is correct
30 Correct 665 ms 492 KB Output is correct
31 Correct 598 ms 400 KB Output is correct
32 Correct 625 ms 612 KB Output is correct
33 Correct 635 ms 400 KB Output is correct
34 Correct 476 ms 648 KB Output is correct
35 Correct 653 ms 692 KB Output is correct
36 Correct 621 ms 728 KB Output is correct
37 Correct 605 ms 636 KB Output is correct
38 Correct 636 ms 704 KB Output is correct
39 Correct 492 ms 740 KB Output is correct
40 Correct 600 ms 608 KB Output is correct
41 Correct 626 ms 620 KB Output is correct
42 Correct 83 ms 548 KB Output is correct
43 Correct 132 ms 528 KB Output is correct
44 Correct 178 ms 528 KB Output is correct
45 Correct 243 ms 484 KB Output is correct
46 Correct 353 ms 484 KB Output is correct
47 Correct 283 ms 656 KB Output is correct
48 Correct 74 ms 552 KB Output is correct
49 Correct 67 ms 528 KB Output is correct