Submission #417724

# Submission time Handle Problem Language Result Execution time Memory
417724 2021-06-04T08:08:11 Z Bill_00 Stations (IOI20_stations) C++14
100 / 100
896 ms 888 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1005];
vector<int> labels(1005);
int sz[1005],n;
vector<int>ans;
void dfs(int node,int par=-1){
	sz[node]=1;
	for(int to:adj[node]){
		if(to!=par){
			dfs(to,node);
			sz[node]+=sz[to];	
		} 
	}
}
void solve(bool flag,int node,int l,int r,int par=-1){
	labels[node]=(flag?l:r);
	if(flag) l++;
	for(int to:adj[node]){
		if(to!=par){
			solve(flag^1,to,l,l+sz[to]-1,node);
			l=l+sz[to];
		}
	}
}
vector<int> label(int N, int k, vector<int> u, vector<int> v) {
	n=N;
	for(int i=0;i<n;i++){
		sz[i]=0;
		adj[i].clear();
		labels[i]=0;
	}
	ans.clear();
	for(int i=0;i<(n-1);i++){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0);
	solve(1,0,0,n-1);
	for(int i=0;i<n;i++) ans.push_back(labels[i]);
	return ans;
}

int find_next_station(int s, int t, vector<int> c) {
	sort(c.begin(),c.end());
	if(s==0){
		for(int i=0;i<c.size();i++){
			if(c[i]>=t) return c[i];
		}
	}
	if(c.back()<s){
		c.push_back(s);
		for(int i=1;i<(int)(c.size()-1);i++){
			if(c[i]<=t && t<c[i+1]) return c[i];
		}
		return c[0];
	}
	else{
		vector<int>q;
		q.push_back(s);
		for(int i=0;i<c.size();i++){
			q.push_back(c[i]);
		}
		for(int i=1;i<(int)(q.size()-1);i++){
			if(q[i-1]<t && t<=q[i]) return q[i];
		}
		return q.back();
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 499 ms 656 KB Output is correct
2 Correct 421 ms 656 KB Output is correct
3 Correct 896 ms 528 KB Output is correct
4 Correct 654 ms 528 KB Output is correct
5 Correct 574 ms 400 KB Output is correct
6 Correct 440 ms 508 KB Output is correct
7 Correct 471 ms 512 KB Output is correct
8 Correct 3 ms 448 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 454 ms 628 KB Output is correct
2 Correct 511 ms 720 KB Output is correct
3 Correct 829 ms 500 KB Output is correct
4 Correct 635 ms 688 KB Output is correct
5 Correct 585 ms 556 KB Output is correct
6 Correct 444 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 530 ms 836 KB Output is correct
2 Correct 456 ms 524 KB Output is correct
3 Correct 835 ms 520 KB Output is correct
4 Correct 654 ms 512 KB Output is correct
5 Correct 564 ms 400 KB Output is correct
6 Correct 459 ms 648 KB Output is correct
7 Correct 417 ms 524 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 526 ms 400 KB Output is correct
12 Correct 424 ms 772 KB Output is correct
13 Correct 449 ms 732 KB Output is correct
14 Correct 439 ms 528 KB Output is correct
15 Correct 56 ms 656 KB Output is correct
16 Correct 66 ms 716 KB Output is correct
17 Correct 103 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 428 KB Output is correct
2 Correct 645 ms 400 KB Output is correct
3 Correct 577 ms 516 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 558 ms 400 KB Output is correct
8 Correct 856 ms 528 KB Output is correct
9 Correct 696 ms 528 KB Output is correct
10 Correct 582 ms 428 KB Output is correct
11 Correct 6 ms 468 KB Output is correct
12 Correct 6 ms 476 KB Output is correct
13 Correct 5 ms 476 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 502 ms 556 KB Output is correct
17 Correct 512 ms 528 KB Output is correct
18 Correct 502 ms 528 KB Output is correct
19 Correct 491 ms 520 KB Output is correct
20 Correct 493 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 656 KB Output is correct
2 Correct 468 ms 776 KB Output is correct
3 Correct 863 ms 512 KB Output is correct
4 Correct 642 ms 400 KB Output is correct
5 Correct 613 ms 520 KB Output is correct
6 Correct 428 ms 648 KB Output is correct
7 Correct 428 ms 520 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 440 ms 632 KB Output is correct
12 Correct 511 ms 520 KB Output is correct
13 Correct 857 ms 400 KB Output is correct
14 Correct 626 ms 520 KB Output is correct
15 Correct 622 ms 536 KB Output is correct
16 Correct 489 ms 708 KB Output is correct
17 Correct 570 ms 528 KB Output is correct
18 Correct 470 ms 524 KB Output is correct
19 Correct 470 ms 888 KB Output is correct
20 Correct 424 ms 528 KB Output is correct
21 Correct 65 ms 528 KB Output is correct
22 Correct 75 ms 656 KB Output is correct
23 Correct 106 ms 656 KB Output is correct
24 Correct 5 ms 596 KB Output is correct
25 Correct 6 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 629 ms 544 KB Output is correct
30 Correct 618 ms 500 KB Output is correct
31 Correct 491 ms 516 KB Output is correct
32 Correct 533 ms 600 KB Output is correct
33 Correct 514 ms 400 KB Output is correct
34 Correct 336 ms 528 KB Output is correct
35 Correct 423 ms 772 KB Output is correct
36 Correct 429 ms 760 KB Output is correct
37 Correct 482 ms 632 KB Output is correct
38 Correct 458 ms 652 KB Output is correct
39 Correct 410 ms 644 KB Output is correct
40 Correct 436 ms 632 KB Output is correct
41 Correct 481 ms 628 KB Output is correct
42 Correct 63 ms 656 KB Output is correct
43 Correct 104 ms 680 KB Output is correct
44 Correct 139 ms 528 KB Output is correct
45 Correct 159 ms 528 KB Output is correct
46 Correct 309 ms 520 KB Output is correct
47 Correct 305 ms 496 KB Output is correct
48 Correct 63 ms 656 KB Output is correct
49 Correct 62 ms 656 KB Output is correct