Submission #838608

#TimeUsernameProblemLanguageResultExecution timeMemory
838608ma_moutahidStations (IOI20_stations)C++17
Compilation error
0 ms0 KiB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<vi>
#define pi pair<int,int>

vi l;
vii g;
int p;
int ps;
void dfs(int node, int parent,int d){
	
	for(int child:g[node]){
		if(child==parent)continue;
		dfs(child,node,d+1);
	}
	l[node]=p*ps+d+1;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	g.clear();
	g.resize(2*n);
	l.resize(n);
	std::vector<int> labels(n);
	for(int i=0;i<n-1;i++){
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	int found=-1;
	for(int i=0;i<n;i++){
		if(g[n].size()>1){
			found =i;
			break;
		}
	}
	if(found!=-1){
		int ps=1000;
		for(int i=0;i<ps;i++){
			p=i;
			dfs(g[found][i],found,0);
		}
	}
	else {
		ps=0;
		p=0;
		dfs(0,-1,0);
	}
	return l;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(s==0){
		return t/1000;
	}
	if(t/1000 !=s/1000)return s-1;
	if(t%1000>s%1000)return s++;
	else return s--;
}
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<vi>
#define pi pair<int,int>

vi l;
vii g;
int p;
int ps;
void dfs(int node, int parent,int d){
	
	for(int child:g[node]){
		if(child==parent)continue;
		dfs(child,node,d+1);
	}
	l[node]=p*ps+d+1;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	g.clear();
	g.resize(2*n);
	l.resize(n);
	std::vector<int> labels(n);
	for(int i=0;i<n-1;i++){
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	int found=-1;
	for(int i=0;i<n;i++){
		if(g[n].size()>1){
			found =i;
			break;
		}
	}
	if(found!=-1){
		int ps=1000;
		for(int i=0;i<ps;i++){
			p=i;
			dfs(g[found][i],found,0);
		}
	}
	else {
		ps=0;
		p=0;
		dfs(0,-1,0);
	}
	return l;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(s==0){
		return t/1000;
	}
	if(t/1000 !=s/1000)return s-1;
	if(t%1000>s%1000)return s++;
	else return s--;
}

Compilation message (stderr)

stations.cpp:69:4: error: redefinition of 'std::vector<int> l'
   69 | vi l;
      |    ^
stations.cpp:9:4: note: 'std::vector<int> l' previously declared here
    9 | vi l;
      |    ^
stations.cpp:70:5: error: redefinition of 'std::vector<std::vector<int> > g'
   70 | vii g;
      |     ^
stations.cpp:10:5: note: 'std::vector<std::vector<int> > g' previously declared here
   10 | vii g;
      |     ^
stations.cpp:71:5: error: redefinition of 'int p'
   71 | int p;
      |     ^
stations.cpp:11:5: note: 'int p' previously declared here
   11 | int p;
      |     ^
stations.cpp:72:5: error: redefinition of 'int ps'
   72 | int ps;
      |     ^~
stations.cpp:12:5: note: 'int ps' previously declared here
   12 | int ps;
      |     ^~
stations.cpp:73:6: error: redefinition of 'void dfs(int, int, int)'
   73 | void dfs(int node, int parent,int d){
      |      ^~~
stations.cpp:13:6: note: 'void dfs(int, int, int)' previously defined here
   13 | void dfs(int node, int parent,int d){
      |      ^~~
stations.cpp:82:18: error: redefinition of 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)'
   82 | std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
      |                  ^~~~~
stations.cpp:22:18: note: 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)' previously defined here
   22 | std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
      |                  ^~~~~
stations.cpp:113:5: error: redefinition of 'int find_next_station(int, int, std::vector<int>)'
  113 | int find_next_station(int s, int t, std::vector<int> c) {
      |     ^~~~~~~~~~~~~~~~~
stations.cpp:53:5: note: 'int find_next_station(int, int, std::vector<int>)' previously defined here
   53 | int find_next_station(int s, int t, std::vector<int> c) {
      |     ^~~~~~~~~~~~~~~~~