Submission #1070612

#TimeUsernameProblemLanguageResultExecution timeMemory
1070612andrei_iorgulescuStations (IOI20_stations)C++14
100 / 100
631 ms1188 KiB
#include <bits/stdc++.h>
#include "stations.h"
#warning That's not FB, that's my FB

using namespace std;

vector<int> g[1005];
int h[1005], pre[1005], post[1005], tmp, tmp2;
bool viz[1005];

void dfs(int nod, int tata)
{
    viz[nod] = true;
    //cout << "ya" << nod << endl;
    if (h[nod] % 2 == 0)
    {
        tmp++;
        pre[nod] = tmp;
    }
    for (auto vecin : g[nod])
    {
        if (vecin != tata)
        {
            h[vecin] = 1 + h[nod];
            dfs(vecin, nod);
        }
    }
    if (h[nod] % 2 == 1)
    {
        tmp++;
        post[nod] = tmp;
    }
}

vector<int> label (int n, int k, vector<int> u, vector<int> v)
{
    for (int i = 0; i < n; i++)
        g[i].clear(), viz[i] = false;
    for (int i = 0; i < n - 1; i++)
        g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
    vector<int> ans(n);
    h[0] = 0;
    tmp = -1;
    tmp2 = -1;
    //cout << "ya" << endl;
    dfs(0, -1);
    //for (int i = 0; i < n; i++)
      //  cout << pre[i] << ' ' << post[i] << endl;
    for (int i = 0; i < n; i++)
    {
        if (h[i] % 2 == 0)
            ans[i] = pre[i];
        else
            ans[i] = post[i];
    }
    vector<pair<int,int>> pans;
    for (int i = 0; i < n; i++)
        pans.push_back({ans[i],i});
    sort(pans.begin(), pans.end());
    for (int i = 0; i < n; i++)
        ans[pans[i].second] = i;
    //for (int i = 0; i < n; i++)
      //  cout << ans[i] << '\n';
    return ans;
}

int find_next_station(int s, int f, vector<int> c)
{
    sort(c.begin(), c.end());
    if (c.size() == 1)
        return c[0];
    if (s < c[0])
    {
        ///pre
        int mxf = c[c.size() - 2];
        if (f > s and f <= mxf)
        {
            int pz;
            for (int i = c.size() - 2; i >= 0; i--)
                if (c[i] >= f)
                    pz = i;
            return c[pz];
        }
        else
            return c.back();
    }
    else
    {
        ///post
        int mnf = c[1];
        if (f >= mnf and f < s)
        {
            int pz;
            for (int i = 1; i < c.size(); i++)
                if (c[i] <= f)
                    pz = i;
            return c[pz];
        }
        else
            return c[0];
    }
}

Compilation message (stderr)

stations.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:94:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for (int i = 1; i < c.size(); i++)
      |                             ~~^~~~~~~~~~
stations.cpp:97:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   97 |             return c[pz];
      |                        ^
stations.cpp:82:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   82 |             return c[pz];
      |                        ^
#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...