Submission #432005

# Submission time Handle Problem Language Result Execution time Memory
432005 2021-06-17T18:59:22 Z gonengazit Stations (IOI20_stations) C++14
0 / 100
859 ms 736 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define x first
#define y second
vector<int> labels;
vector<vector<int>> g;
int tme;
void dfs1(int i,int f=0,int t=0){
	if(t==0){
		labels[i]=++tme;
	}
	for(auto u:g[i]){
		if(u!=f){
			dfs1(u,i,(t+1)%2);
		}
	}
	if(t==1){
		labels[i]=++tme;
	}
}

// void dfs1(int i, int f=0){
// 	int tin=++tme;
// 	for(auto u:g[i]){
// 		if(u!=f){
// 			dfs1(u,i);
// 		}
// 	}
// 	int tout=tme;
// 	labels[i]=tin*1000+tout;
// }
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	tme=-1;
	labels.assign(n,-1);
	g.assign(n,vector<int>());
	for(int i=0; i<n-1; i++){
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}

	dfs1(0);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	
	int r=0;
	for(auto i:c){
		if(i<s){
			r=1;
		}
	}
	vector<pair<ii,int>> cld;
	int f=-1;
	if(r==0){
		int prev=s;
		for(auto i:c){
			int k=i;
			cld.emplace_back(ii(prev+1,k),i);
			prev=k;
		}
		if(s!=0){
			f=cld.back().y;
			cld.pop_back();
		}
	}
	else{
		f=c[0];
		for(int j=1; j<c.size(); j++){
			int i=c[j];
			int k=i;
			if(!cld.empty())
				cld.back().x.y=k-1;
			cld.emplace_back(ii(k,-1),i);
		}
		if(!cld.empty()){
			cld.back().x.y=s;
		}
	}

	t/=2;

	for(auto i:cld){
		if(i.x.x<=t&&i.x.y>=t){
			return i.y;
		}
	}
	return f;
}
/*
1
5 100
0 1
1 2
1 3
2 4
3
0 1 2
1 2 2
1 4 2*/

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int j=1; j<c.size(); j++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 508 ms 648 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 522 ms 736 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 859 ms 400 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 537 ms 620 KB Wrong query response.
2 Halted 0 ms 0 KB -