Submission #393080

# Submission time Handle Problem Language Result Execution time Memory
393080 2021-04-22T16:55:16 Z REALITYNB Stations (IOI20_stations) C++14
8 / 100
1144 ms 656 KB
#include <bits/stdc++.h> 
#include "stations.h"
#define pii pair<int,int> 
#define in first 
#define out second
#define mp make_pair 
using namespace std; 

vector<int> label(int n ,int k , vector<int> u , vector<int> v){
	vector<int> ans(n) ; 
	vector<int> adj[n] ; 
	for(int i=0;i<n-1;i++) {
		adj[u[i]].push_back(v[i]) ; 
		adj[v[i]].push_back(u[i]) ; 
	}
	int tim =0; 
	function<void(int,int,int)> dfs = [&](int a, int p,int num ){
		ans[a]=num ; 
		bool flg = 0 ; 
		for(int&x:adj[a]){
			if(x!=p) {
				dfs(x,a,num*2+flg) ; 
				flg=1;
			}
		}
	}; 
	dfs(0,0,1); 
	return ans ; 
}
vector<int> get_root_path(int x){
	vector<int> a ; 
	while(x){
		a.push_back(x) ; 
		x/=2 ;
	}
	reverse(a.begin(),a.end()) ; 
	return a ; 
}
vector<int> get_path(int s , int t){
	vector<int> a = get_root_path(s) , b = get_root_path(t) ; 
	//for(int x : a) cout << x << " "; 
	int lca = 0 ;

	for(int i=0;i<min(a.size(),b.size());i++){
		if(b[i]==a[i]){
			lca = i ; 
			continue ; 
		} 
	}
	vector<int> ans ; 
	for(int i=a.size()-1;i>lca;i--){
		ans.push_back(a[i]) ; 
	}
	ans.push_back(a[lca]) ; 
	/*cout << endl ; 
	for(int x : b) cout <<  x<< " " ; 
		cout << lca << " "; */
	for(int i=lca+1;i<b.size();i++) ans.push_back(b[i]) ; 
	//cout << endl ; 
	return ans ; 
}
int find_next_station(int s ,int t, vector<int> ne){
	vector<int>  a= get_path(s,t) ; 
	return a[1] ; 
}
/*int main(){
	cout << "4 7 :" ;
	vector<int> a = get_path(4,7) ; 
	for(int x : a) cout << x << " "; 
	cout << endl ; 
	return 0 ; 
}*/

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:16:6: warning: unused variable 'tim' [-Wunused-variable]
   16 |  int tim =0;
      |      ^~~
stations.cpp: In function 'std::vector<int> get_path(int, int)':
stations.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   44 |  for(int i=0;i<min(a.size(),b.size());i++){
      |              ~^~~~~~~~~~~~~~~~~~~~~~~
stations.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=lca+1;i<b.size();i++) ans.push_back(b[i]) ;
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 460 KB Invalid labels (duplicates values). scenario=2, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 541 ms 492 KB Output is correct
2 Correct 607 ms 492 KB Output is correct
3 Correct 1085 ms 404 KB Output is correct
4 Correct 905 ms 528 KB Output is correct
5 Correct 756 ms 400 KB Output is correct
6 Correct 683 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 420 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1130 ms 400 KB Output is correct
2 Correct 736 ms 528 KB Output is correct
3 Correct 762 ms 400 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 5 ms 488 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 788 ms 656 KB Output is correct
8 Correct 1144 ms 400 KB Output is correct
9 Correct 793 ms 400 KB Output is correct
10 Correct 757 ms 496 KB Output is correct
11 Incorrect 1 ms 200 KB Invalid labels (duplicates values). scenario=0, label=5
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 416 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -