Submission #304939

#TimeUsernameProblemLanguageResultExecution timeMemory
304939galcaStations (IOI20_stations)C++14
0 / 100
6 ms384 KiB
#include "stations.h" #include <vector> using namespace std; int label_nodes(vector<vector<int>>& nodes, vector<int>& labels, bool isMin, int id, int me, int father) { if (nodes[me].size() == 1) { // a leaf labels[me] = id; return id+1; } if (isMin) { labels[me] = id; int next_id = id + 1; for (int i = 0; i < nodes[me].size(); i++) { if (nodes[me][i] != father) { next_id = label_nodes(nodes, labels, !isMin, next_id, nodes[me][i], me); } } return next_id; } else { int next_id = id + 1; for (int i = 0; i < nodes[me].size(); i++) { if (nodes[me][i] != father) { next_id = label_nodes(nodes, labels, !isMin, next_id, nodes[me][i], me); } } labels[me] = next_id; return next_id + 1; } } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { vector<vector<int>> nodes(n); vector<int> labels(n); for (int i = 0; i < n; i++) { vector<int> edges; nodes.push_back(edges); } for (int i = 0; i < u.size(); i++) { nodes[u[i]].push_back(v[i]); nodes[v[i]].push_back(u[i]); } int root = 0; labels[0] = 0; return labels; } int find_next_station(int s, int t, std::vector<int> c) { bool isMin = c[0] > s; if (isMin) { int father = c[c.size()-1]; if (t < s) { return father; } for (int i = 0; i < c.size(); i++) { if (t < c[i]) return c[i]; } return father; } else { int father = c[0]; if (t > s) { return father; } if (t < c[0]) { return father; } for (int i = 1; i < c.size(); i++) { if (t < c[i]) return c[i - 1]; } return c[c.size()-1]; } return c[0]; }

Compilation message (stderr)

stations.cpp: In function 'int label_nodes(std::vector<std::vector<int> >&, std::vector<int>&, bool, int, int, int)':
stations.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for (int i = 0; i < nodes[me].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
stations.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for (int i = 0; i < nodes[me].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
stations.cpp:46:6: warning: unused variable 'root' [-Wunused-variable]
   46 |  int root = 0;
      |      ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int i = 0; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 1; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...