Submission #321506

# Submission time Handle Problem Language Result Execution time Memory
321506 2020-11-12T15:32:00 Z katearima Stations (IOI20_stations) C++14
0 / 100
54 ms 1004 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
vector<vector<int>> a(N);
vector<int> ans(N);
int i,n,k,m,x,j,t;
void DFS(vector<vector<int>> a, int x,int y,int d){
	if(d%2==0) {ans[y]=t; t++;}
	for(int i=0; i<a[y].size(); i++){
		if(a[y][i]==x) continue;
		DFS(a,y,a[y][i],d+1);
	}
	if(d%2!=0) {ans[y]=t; t++;}
	
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> label(n);
	for(i=0; i<n-1; i++){
		a[u[i]].push_back(v[i]);
		a[v[i]].push_back(u[i]);
	}
    t=0;
	DFS(a,-1,0,0);
	for(i=0; i<n; i++){
		cout<<ans[i]<<endl;
	}
	for(i=0; i<n; i++) label[i]=ans[i];
	ans.clear(); a.clear();
	return label;
}

int find_next_station(int s, int t, vector<int> c) {
	bool parent=true;
	int ans;
	
	if(s<c[0]){
		c.insert(c.begin(),s);
		for(int i=1; i<c.size()-1; i++){
			if(t<=c[i] && t>=c[i-1]+1) {ans=c[i]; parent=false;}
		}
		if(parent) ans=c[c.size()-1];
	}
	else{
		c.push_back(s);
		for(int i=1; i<c.size()-1; i++){
			if(t>=c[i] && t<=c[i+1]-1) {ans=c[i]; parent=false;}
			if(parent) ans=c[0];
		}
		
	}
	return ans;
}

Compilation message

stations.cpp: In function 'void DFS(std::vector<std::vector<int> >, int, int, int)':
stations.cpp:11:16: 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<a[y].size(); i++){
      |               ~^~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i=1; i<c.size()-1; i++){
      |                ~^~~~~~~~~~~
stations.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=1; i<c.size()-1; i++){
      |                ~^~~~~~~~~~~
stations.cpp:53:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |  return ans;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 1004 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -