Submission #307381

# Submission time Handle Problem Language Result Execution time Memory
307381 2020-09-28T03:42:26 Z arthur_nascimento Stations (IOI20_stations) C++14
5 / 100
988 ms 1048 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define debug
#define maxn 1010
int ini[maxn];
int fim[maxn];
int h[maxn];
vector<int> L[maxn];

int cur = 0;
void dfs(int x,int p=-1){
	debug("dfs %d\n",x);
	ini[x] = cur++;
	for(int i : L[x])
		if(i != p){
			h[i] = 1 + h[x];
			dfs(i,x);
		}
	//fim[x] = cur++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	cur = 0;
	for(int i=0;i<n;i++)
		L[i].clear(), h[i] = ini[i] = fim[i] = 0;
	for(int i=0;i<n-1;i++){
		L[u[i]].pb(v[i]);
		L[v[i]].pb(u[i]);
	}
	for(int i=0;i<n;i++){
		if(L[i].size() == 1){
			dfs(i);
			break;
		}
	}
	
	vector<int> ret;
	for(int i=0;i<n;i++){
		if(h[i]%2 == 0)
			ret.pb(ini[i]);
		else
			ret.pb(ini[i]);
	}
	for(int i : ret)
		debug("%d ",i);
	debug("\n");
	return ret;
}

int find_next_station(int s, int t, std::vector<int> c) {

	if(t > s) return s+1;
	else return s-1;

	debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
	if(c.size() == 1) return c[0];
	sort(c.begin(), c.end());
	if(s < c[0]){
		// S é entrada, c[i] é saida
		int pai = c[c.size()-1];
		if(t < s) return pai;
		if(c.size() >= 2 && t > c[c.size()-2]) return pai;
		for(int i=0;i<c.size();i++){
			if(t <= c[i])
				return c[i];
		}
		
	}
	else {
		// S é saida, c[i] é entrada
		int pai = c[0];
		if(t > s) return pai;
		if(t < c[1]) return pai;
		for(int i=1;i<c.size()-1;i++){
			if(t < c[i+1]) return c[i];
		}
		return c[c.size()-1];
	}
}

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:14:8: warning: left operand of comma operator has no effect [-Wunused-value]
   14 |  debug("dfs %d\n",x);
      |        ^~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:47:9: warning: left operand of comma operator has no effect [-Wunused-value]
   47 |   debug("%d ",i);
      |         ^~~~~
stations.cpp:48:8: warning: statement has no effect [-Wunused-value]
   48 |  debug("\n");
      |       ~^~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:8: warning: left operand of comma operator has no effect [-Wunused-value]
   57 |  debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
      |        ^~~~~~~~~~~~
stations.cpp:57:23: warning: right operand of comma operator has no effect [-Wunused-value]
   57 |  debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
      |                       ^
stations.cpp:57:48: warning: left operand of comma operator has no effect [-Wunused-value]
   57 |  debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
      |                                                ^~~~~
stations.cpp:57:64: warning: statement has no effect [-Wunused-value]
   57 |  debug("qr %d %d ~",s,t); for(int i : c) debug("%d ",i); debug("\n");
      |                                                               ~^~~~~
stations.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:76:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i=1;i<c.size()-1;i++){
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 529 ms 768 KB Output is correct
2 Correct 457 ms 1024 KB Output is correct
3 Correct 891 ms 1008 KB Output is correct
4 Correct 670 ms 864 KB Output is correct
5 Correct 592 ms 1024 KB Output is correct
6 Correct 468 ms 1028 KB Output is correct
7 Correct 492 ms 776 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 860 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 485 ms 832 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 555 ms 1048 KB Output is correct
2 Correct 473 ms 1024 KB Output is correct
3 Correct 988 ms 768 KB Output is correct
4 Correct 767 ms 860 KB Output is correct
5 Correct 778 ms 860 KB Output is correct
6 Correct 560 ms 1024 KB Output is correct
7 Correct 523 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 872 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Incorrect 567 ms 768 KB Wrong query response.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 925 ms 768 KB Output is correct
2 Correct 684 ms 768 KB Output is correct
3 Correct 587 ms 768 KB Output is correct
4 Correct 3 ms 876 KB Output is correct
5 Correct 6 ms 868 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Incorrect 574 ms 768 KB Wrong query response.
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 527 ms 768 KB Output is correct
2 Correct 449 ms 768 KB Output is correct
3 Correct 869 ms 768 KB Output is correct
4 Correct 680 ms 868 KB Output is correct
5 Correct 629 ms 868 KB Output is correct
6 Correct 444 ms 1016 KB Output is correct
7 Correct 438 ms 772 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Incorrect 463 ms 768 KB Wrong query response.
12 Halted 0 ms 0 KB -