Submission #696735

#TimeUsernameProblemLanguageResultExecution timeMemory
696735garam1732Stations (IOI20_stations)C++14
0 / 100
4 ms592 KiB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[1010];

void dfs(int here, int par, vector<int>& labels) {
    for(int there : adj[here]) {
        if(there == par) continue;
        labels[there] = labels[here] + 1000;
        dfs(there, here, labels);
    }
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for(int i = 0; i < n; i++) adj[i].clear();

	for(int i = 0; i < u.size(); i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}

	int idx = 0;
	for(int i = 0; i < n; i++) {
        if(adj[i].size() > 2) {
            idx = i;
            break;
        }
	}

	int d = adj[idx].size();
	labels[idx] = 0;
	for(int i = 0; i < d; i++) {
        int here = adj[idx][i]; labels[here] = i+1;
        dfs(here, idx, labels);
	}
}

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

	if(s > t) return s-1000;
	return s+1000;
}

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
stations.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
   38 | }
      | ^
#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...