Submission #376434

# Submission time Handle Problem Language Result Execution time Memory
376434 2021-03-11T13:08:58 Z mosiashvililuka Stations (IOI20_stations) C++14
100 / 100
1007 ms 1284 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tim,lf[1009],rg[1009],dep[1009],pi;
vector <int> v[1009];
pair <int, int> p[1009];
void dfs(int q, int w){
	if(w!=-1) dep[q]=dep[w]+1;
	tim++;
	lf[q]=tim;
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if((*it)==w) continue;
		dfs((*it),q);
	}
	tim++;
	rg[q]=tim;
	if(dep[q]%2==0){
		pi++;
		p[pi].first=lf[q];
		p[pi].second=q;
	}else{
		pi++;
		p[pi].first=rg[q];
		p[pi].second=q;
	}
}
vector<int> label(int n, int kk, vector<int> U, vector<int> V) {
	vector<int> labels(n);
	pi=0;tim=0;
	for(i=0; i<=n; i++){
		v[i].clear();
		dep[i]=0;
		lf[i]=rg[i]=0;
	}
	for(i=0; i<n-1; i++){
		v[U[i]].push_back(V[i]);
		v[V[i]].push_back(U[i]);
	}
	//cout<<pi<<" ra "<<endl;
	dfs(0,-1);
	sort(p+1,p+pi+1);
	//cout<<pi<<" kd "<<endl;
	for(i=1; i<=pi; i++){
		//cout<<p[i].first<<" "<<p[i].second<<endl;
		labels[p[i].second]=i-1;
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> C) {
	for(i=0; i<C.size(); i++){
		if(C[i]==t){
			return t;
		}
	}
	e=0;
	for(i=0; i<C.size(); i++){
		if(C[i]>s){
			e=1;
			break;
		}
	}
	if(e==0){
		sort(C.begin(),C.end());
		for(i=1; i<C.size(); i++){
			if(t>=C[i-1]&&t<C[i]){
				return C[i-1];
			}
		}
		if(t>=C[C.size()-1]&&t<s){
			return C[C.size()-1];
		}
		return C[0];
	}else{
		sort(C.begin(),C.end());
		if(s==0){
			for(i=0; i<C.size(); i++){
				if(t<=C[i]){
					return C[i];
				}
			}
		}else{
			if(t<s){
				return C[C.size()-1];
			}
			for(i=0; i<C.size(); i++){
				if(i+1>=C.size()) break;
				if(t<=C[i]){
					return C[i];
				}
			}
			return C[C.size()-1];
		}
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(i=0; i<C.size(); i++){
      |           ~^~~~~~~~~
stations.cpp:58:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(i=0; i<C.size(); i++){
      |           ~^~~~~~~~~
stations.cpp:66:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for(i=1; i<C.size(); i++){
      |            ~^~~~~~~~~
stations.cpp:78:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |    for(i=0; i<C.size(); i++){
      |             ~^~~~~~~~~
stations.cpp:87:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for(i=0; i<C.size(); i++){
      |             ~^~~~~~~~~
stations.cpp:88:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     if(i+1>=C.size()) break;
      |        ~~~^~~~~~~~~~
stations.cpp:96:1: warning: control reaches end of non-void function [-Wreturn-type]
   96 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 572 ms 992 KB Output is correct
2 Correct 441 ms 1200 KB Output is correct
3 Correct 871 ms 936 KB Output is correct
4 Correct 680 ms 936 KB Output is correct
5 Correct 599 ms 864 KB Output is correct
6 Correct 457 ms 864 KB Output is correct
7 Correct 514 ms 1100 KB Output is correct
8 Correct 3 ms 944 KB Output is correct
9 Correct 4 ms 864 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 868 KB Output is correct
2 Correct 622 ms 1136 KB Output is correct
3 Correct 959 ms 864 KB Output is correct
4 Correct 760 ms 992 KB Output is correct
5 Correct 713 ms 736 KB Output is correct
6 Correct 508 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 582 ms 1072 KB Output is correct
2 Correct 483 ms 1200 KB Output is correct
3 Correct 957 ms 736 KB Output is correct
4 Correct 740 ms 828 KB Output is correct
5 Correct 661 ms 864 KB Output is correct
6 Correct 586 ms 864 KB Output is correct
7 Correct 467 ms 1096 KB Output is correct
8 Correct 3 ms 936 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 2 ms 936 KB Output is correct
11 Correct 625 ms 1236 KB Output is correct
12 Correct 472 ms 1072 KB Output is correct
13 Correct 534 ms 1076 KB Output is correct
14 Correct 526 ms 884 KB Output is correct
15 Correct 54 ms 864 KB Output is correct
16 Correct 66 ms 864 KB Output is correct
17 Correct 122 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1000 ms 1120 KB Output is correct
2 Correct 675 ms 936 KB Output is correct
3 Correct 772 ms 1064 KB Output is correct
4 Correct 3 ms 864 KB Output is correct
5 Correct 4 ms 736 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 659 ms 936 KB Output is correct
8 Correct 1007 ms 864 KB Output is correct
9 Correct 700 ms 736 KB Output is correct
10 Correct 670 ms 936 KB Output is correct
11 Correct 4 ms 864 KB Output is correct
12 Correct 7 ms 736 KB Output is correct
13 Correct 5 ms 864 KB Output is correct
14 Correct 4 ms 736 KB Output is correct
15 Correct 2 ms 864 KB Output is correct
16 Correct 538 ms 864 KB Output is correct
17 Correct 601 ms 936 KB Output is correct
18 Correct 586 ms 936 KB Output is correct
19 Correct 546 ms 864 KB Output is correct
20 Correct 540 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 633 ms 1076 KB Output is correct
2 Correct 459 ms 948 KB Output is correct
3 Correct 905 ms 936 KB Output is correct
4 Correct 846 ms 936 KB Output is correct
5 Correct 742 ms 864 KB Output is correct
6 Correct 614 ms 992 KB Output is correct
7 Correct 677 ms 864 KB Output is correct
8 Correct 3 ms 944 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
11 Correct 547 ms 868 KB Output is correct
12 Correct 585 ms 736 KB Output is correct
13 Correct 895 ms 864 KB Output is correct
14 Correct 682 ms 936 KB Output is correct
15 Correct 686 ms 736 KB Output is correct
16 Correct 475 ms 884 KB Output is correct
17 Correct 681 ms 992 KB Output is correct
18 Correct 585 ms 1248 KB Output is correct
19 Correct 466 ms 1204 KB Output is correct
20 Correct 561 ms 864 KB Output is correct
21 Correct 74 ms 864 KB Output is correct
22 Correct 69 ms 736 KB Output is correct
23 Correct 143 ms 876 KB Output is correct
24 Correct 7 ms 736 KB Output is correct
25 Correct 7 ms 864 KB Output is correct
26 Correct 8 ms 864 KB Output is correct
27 Correct 5 ms 736 KB Output is correct
28 Correct 2 ms 992 KB Output is correct
29 Correct 635 ms 736 KB Output is correct
30 Correct 574 ms 896 KB Output is correct
31 Correct 526 ms 944 KB Output is correct
32 Correct 638 ms 736 KB Output is correct
33 Correct 592 ms 864 KB Output is correct
34 Correct 435 ms 1284 KB Output is correct
35 Correct 450 ms 1064 KB Output is correct
36 Correct 494 ms 1240 KB Output is correct
37 Correct 532 ms 864 KB Output is correct
38 Correct 469 ms 1104 KB Output is correct
39 Correct 467 ms 992 KB Output is correct
40 Correct 461 ms 1204 KB Output is correct
41 Correct 581 ms 1116 KB Output is correct
42 Correct 76 ms 880 KB Output is correct
43 Correct 110 ms 736 KB Output is correct
44 Correct 170 ms 1112 KB Output is correct
45 Correct 211 ms 992 KB Output is correct
46 Correct 354 ms 736 KB Output is correct
47 Correct 321 ms 1236 KB Output is correct
48 Correct 64 ms 1084 KB Output is correct
49 Correct 73 ms 992 KB Output is correct