Submission #436434

#TimeUsernameProblemLanguageResultExecution timeMemory
436434yuto1115Stations (IOI20_stations)C++17
16 / 100
1228 ms640 KiB
#include "stations.h"
#include "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

vi label(int n, int k, vi u, vi v) {
    vvi G(n);
    rep(i, n - 1) {
        G[u[i]].pb(v[i]);
        G[v[i]].pb(u[i]);
    }
    vi ls;
    auto dfs = [&](auto &dfs, int now, int p) -> void {
        ls.pb(now);
        for (int nx : G[now]) {
            if (nx == p) continue;
            dfs(dfs, nx, now);
        }
    };
    int mx = 0, s = 0;
    rep(i, n) if (chmax<int>(mx, G[i].size())) s = i;
    vi res(n);
    int idx = 1000;
    for (int i : G[s]) {
        dfs(dfs, i, s);
        int now = idx;
        for (int j : ls) res[j] = now++;
        idx += 1000;
        assert(now < idx);
        ls.clear();
    }
    return res;
}

int find_next_station(int s, int t, vi c) {
    if (s == 0) {
        for (int i : c) {
            if (i / 1000 == t / 1000) return i;
        }
        assert(false);
    }
    assert(c.size() <= 2);
    int u, d;
    for (int i : c) {
        if (i < s) u = i;
        else d = i;
    }
    if (s / 1000 == t / 1000) {
        return (s < t ? d : u);
    } else {
        return u;
    }
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:78:12: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |     int u, d;
      |            ^
#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...