Submission #320504

# Submission time Handle Problem Language Result Execution time Memory
320504 2020-11-08T21:59:14 Z Ambok Stations (IOI20_stations) C++14
0 / 100
938 ms 1236 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
int coun=0; 
vector < vector <int> > vec(2000);
vector <int> L(2000);
void dfs (int x, int y, int h)
	{
		if (h%2==0) L[x]=coun;
		coun++;
		for (int i=0; i<vec[x].size(); i++)
		{
			if (vec[x][i]==y) continue;
			dfs(vec[x][i], x, h+1);
		}
		if (h%2==1) L[x]=coun;
		h--; coun++;
	}
vector <int> label(int n, int k, vector <int> u, vector <int> v)
{
	int s, h, i;
	L.resize(n);
	vec.resize(n);
	
	for (i=0; i<n; i++)
	{
		vec[i].clear();
	}
	
	for (i=0; i<n-1; i++)
	{
		vec[u[i]].push_back(v[i]);
		vec[v[i]].push_back(u[i]);
	}
	
	L[0]=0; coun=0;
	dfs (0, -1, 0);
	
	vector < vector < int > > d;
	for(int i = 0; i < n; ++i) 
	{
	    d.push_back({L[i], i});
	}
	sort(d.begin(), d.end());
	
	for(int i=0; i<n; i++) 
	{
	    L[d[i][1]] = i;
	}
	
	return L;
}
int find_next_station(int s, int t, vector <int>c)
{
	int n=c.size(), i;
	int in[n+1], out[n+1];
	
	
    sort(c.begin(), c.end()); 
	
	if (n==1) return c[0];
	
	if (s==0)
	{
		in[n]=s;
		out[n]=c[n-1]+1;
		
		for (i=0; i<n; i++)
		out[i]=c[i];
		
		in[0]=s+1;
		for (i=1; i<n; i++)
		{
			in[i]=out[i-1]+1;
		}
		
		for (i=0; i<n; i++)
			{
				if (t>=in[i] && t<=out[i]) return c[i];
			}
	}
	
	if (s>c[n-1])
	{
		in[n]=c[1]-1;
		out[n]=s;
		
		for (i=0; i<n; i++)
		in[i]=c[i];
		
		for (i=1; i<n; i++)
		{
			out[i]=in[i+1]-1;
		}
	
		for (i=1; i<n; i++)
			{
				if (t>=in[i] && t<=out[i]) return c[i];
			}
		
		return c[0];
	}
	else 
	{
		in[n]=s;
		out[n]=c[n-2]+1;
		
		for (i=0; i<n; i++)
		out[i]=c[i];
		in[0]=s+1;
		for (i=1; i<n; i++)
		{
			in[i]=out[i-1]+1;
		}
		
		for (i=0; i<n-1; i++)
			{
				if (t>=in[i] && t<=out[i]) return c[i];
			}
	
		return c[n-1];	
	}
}

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |   for (int i=0; i<vec[x].size(); i++)
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:21:6: warning: unused variable 's' [-Wunused-variable]
   21 |  int s, h, i;
      |      ^
stations.cpp:21:9: warning: unused variable 'h' [-Wunused-variable]
   21 |  int s, h, i;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 532 ms 1220 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 424 ms 992 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 557 ms 1120 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 938 ms 864 KB Output is correct
2 Incorrect 628 ms 864 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 693 ms 1236 KB Wrong query response.
2 Halted 0 ms 0 KB -