Submission #805166

#TimeUsernameProblemLanguageResultExecution timeMemory
805166AndreyStations (IOI20_stations)C++14
0 / 100
652 ms1508 KiB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> yay(0);
vector<int> haha[10001];
int p;

void dfs(int a, int t) {
    yay[a] = p*1000;
    p++;
    for(int i = 0; i < haha[a].size(); i++) {
        if(haha[a][i] != t) {
            dfs(haha[a][i],a);
        }
    }
    yay[a]+=p;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for(int i = 0; i < n; i++) {
        haha[i].clear();
    }
    for(int i = 0; i < n-1; i++) {
        haha[u[i]].push_back(v[i]);
        haha[v[i]].push_back(u[i]);
    }
    p = 0;
    yay.clear();
	for(int i = 0; i < n; i++) {
        yay.push_back(0);
	}
	vector<int> ans(0);
	for(int i = 0; i < n; i++) {
        if(haha[i].size() == 1) {
            dfs(i,-1);
            break;
        }
	}
	for(int i = 0; i < n; i++) {
        ans.push_back(yay[i]);
	}
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    int l,r,x = t/1000;
    if(x < s/1000) {
        return c[0];
    }
    for(int i = 0; i < c.size(); i++) {
        l = c[i]/1000;
        r = c[i]%1000;
        if(x >= l && x <= r) {
            return c[i];
        }
    }
}

Compilation message (stderr)

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i < c.size(); i++) {
      |                    ~~^~~~~~~~~~
stations.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
#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...