Problem:
E: えびちゃんを捕獲せよ
問題
あ　やせいの　えびちゃんが　とびだしてきた！
頂点数 $N$、辺数 $M$ の無向グラフで表されるフィールドがある。頂点は $1$ から $N$ まで、辺は $1$ から $M$ までで、それぞれ番号付けされている。また、各頂点には
a
から
z
の英小文字のいずれかが $1$ つ書かれている。
えびちゃんは任意の頂点に出現する可能性がある。
えびちゃんは、ある頂点に出現した後、すぐに別の頂点へワープして逃げてしまう。
えびちゃんは、次の条件をすべて満たすとき、頂点 $u$ から頂点 $v$ へワープすることができる。
$u$ から $v$ へ、$K$ 本以下の辺を辿って移動できる。
$u$ に書かれた文字と $v$ に書かれた文字が隣り合っている。
「英小文字 $c$ と隣り合っている文字」とは、英小文字のアルファベットを辞書順に並べ、
a
と
z
をつなげて円環状に並べたものの中で $c$ と隣接している $2$ 文字を指す。たとえば、
b
は
a
と
c
に隣り合っており、
z
は
y
と
a
に隣り合っている。
あなたは、いくつかの頂点に罠を設置して、えびちゃんを捕獲する体制を整えることにした。
えびちゃんは罠のある頂点に侵入すると、即座に捕まってしまう。
えびちゃんがどの頂点に現れたとしても身動きが取れないようにするために必要な罠の個数の最小値を求めよ。ただし、身動きが取れないとは、「現れた頂点に罠がある」または「罠のない頂点にワープできない」のいずれかが成り立つことを指す。
入力形式
$N$ $M$ $K$
$c_1$ $c_2$ … $c_N$
$u_1$ $v_1$
…
$u_M$ $v_M$
$1$ 行目には、頂点数 $N$、辺数 $M$、えびちゃんのワープに関する値 $K$ が与えられる。
$2$ 行目には、各頂点に書かれた文字がスペース区切りで与えられる。$c_i$ ($1\leq i\leq N$) は、$i$ 番目の頂点に書かれた文字を表す。
$2+i$ 行目 ($1\leq i\leq M$) には、$i$ 本目の辺の情報が与えられる。頂点 $u_i$ と $v_i$ を双方向に結ぶことを意味する。
制約
$2\leq N\leq 300$
$1\leq M\leq N(N-1)/2$
$1\leq K\leq 300$
$c_i$ ($1\leq i\leq N$) は英小文字である。
多重辺および自己ループは存在しない。
出力形式
答えを一行に出力せよ。
入力例1
5 3 2
a b c d z
1 2
1 3
3 5
出力例1
2
えびちゃんがワープできる頂点の組は $(1, 2)$、$(1, 5)$、$(2, 3)$ であり、例として頂点 $2$ と頂点 $5$ に設置することで目標を達成することができる。また、$1$ 個以下の罠で目標を達成することはできない。なお、頂点 $4$ からはどこにもワープできないため、罠を設置する必要はないことに注意せよ。
入力例2
5 5 1
a b c d z
1 2
1 3
1 4
1 5
3 4
出力例2
2
えびちゃんがワープできる頂点の組は $(1, 2)$、$(1, 5)$、$(3, 4)$ であり、例として頂点 $1$ と頂点 $3$ に設置することで目標を達成することができる。このケースにおいても、$1$ 個以下の罠では目標を達成することはできない。
入力例3
4 6 3
h u p c
1 2
1 3
1 4
2 3
2 4
3 4
出力例3
0
えびちゃんはどの頂点間もワープできないので、罠を用意する必要はない。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define INF 1e8
void warshall_floyd(vector<vector<int>> &M) {
    int n = M.size();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                M[j][k] = min(M[j][k], M[j][i] + M[i][k]);
}

struct edge {
    int to, cap, rev;
};

void add_edge(vector<vector<edge>> &G, int from, int to, int cap) {
    G[from].emplace_back((edge) {to, cap, (int) G[to].size()});
    G[to].emplace_back((edge) {from, 0, (int) G[from].size() - 1});
}

int dfs_f(vector<vector<edge>> &G, vector<bool> &used, int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs_f(G, used, e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(vector<vector<edge>> &G, int s, int t) {
    int flow = 0;
    while (true) {
        vector<bool> used(G.size(), false);
        int f = dfs_f(G, used, s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    FIO
    int n, m, k;
    cin >> n >> m >> k;

    vector<char> c(n);
    for (int i = 0; i < n; i++) cin >> c.at(i);

    vector<vector<int>> M(n, vector<int>(n, INF));

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        M[u][v] = 1;
        M[v][u] = 1;
    }

    warshall_floyd(M);

    vector<vector<edge>> G(2 * n + 2);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (M[i][j] <= k && (c[i] + 1 == c[j] || c[j] + 1 == c[i] || (c[i] == 'a' && c[j] == 'z') || (c[i] == 'z' && c[j] == 'a'))) {
                add_edge(G, i, n + j, 1);
                add_edge(G, j, n + i, 1);
            }
        }
    }

    for (int i = 0; i < n; i++) add_edge(G, 2 * n, i, 1);
    for (int i = 0; i < n; i++) add_edge(G, n + i, 2 * n + 1, 1);

    cout << max_flow(G, 2 * n, 2 * n + 1) / 2 << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 7280
final_rank: 11

code_snippet: #line 1 "3168.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/3168"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#include <iostream>
#include <iomanip>

namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
#line 2 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Utility/U32Pair.hpp"

#line 4 "/home/zawatin/compro/cp-documentation/Src/Utility/U32Pair.hpp"

#include <functional>
#line 7 "/home/zawatin/compro/cp-documentation/Src/Utility/U32Pair.hpp"

namespace zawa {

class U32Pair {
private:
    static constexpr u32 SHIFT{32};
    static constexpr u32 MASK{static_cast<u32>((1LL << SHIFT) - 1)};
    u64 value_{};
public:
    constexpr U32Pair() {}
    constexpr U32Pair(u32 first, u32 second) {
        value_ = (static_cast<u64>(first) << SHIFT) | second;
    }
    constexpr u32 first() const noexcept {
        return static_cast<u32>(value_ >> SHIFT);
    }
    constexpr u32 second() const noexcept {
        return static_cast<u32>(value_ & MASK);
    }
    constexpr u64 combined() const noexcept {
        return value_;
    }
    constexpr U32Pair& operator=(const U32Pair& rhs) {
        value_ = rhs.value_;
        return *this;
    }
    friend constexpr bool operator==(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ == rhs.value_;
    }
    friend constexpr bool operator!=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ != rhs.value_;
    }
    friend constexpr bool operator<(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ < rhs.value_;
    }
    friend constexpr bool operator<=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ <= rhs.value_;
    }
    friend constexpr bool operator>(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ > rhs.value_;
    }
    friend constexpr bool operator>=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ >= rhs.value_;
    }
    friend std::ostream& operator<<(std::ostream& os, const U32Pair& pair) {
        os << '(' << pair.first() << ',' << pair.second() << ')';
        return os;
    }
};

struct U32PairHash {
    usize operator()(const U32Pair& pair) const noexcept {
        return std::hash<u64>{}(pair.combined());
    }
};

} // namespace zawa
#line 5 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#include <algorithm>
#include <cassert>
#include <limits>
#include <type_traits>
#include <vector>
#include <queue>

namespace zawa {

template <class Cap> 
class Dinic {
private:
    static_assert(std::is_signed_v<Cap>, "Cap must be signed");
    usize n_{}, m_{};
    static constexpr u32 invalid() noexcept {
        return std::numeric_limits<u32>::max();
    }
public:
    inline usize size() const noexcept {
        return n_;
    }
    inline usize edgeNumber() const noexcept {
        return m_;
    }
private:
    struct Edge {
        u32 to{}, rev{};
        Cap residual{};
        Edge() = default;
        Edge(u32 to, u32 rev, const Cap& residual) 
            : to{to}, rev{rev}, residual{residual} {}
    };

    std::vector<std::vector<Edge>> g_;
    std::vector<U32Pair> edges_;
    std::vector<u32> label_, cur_;

    bool dualStep(u32 s, u32 t) {
        std::fill(label_.begin(), label_.end(), invalid());
        label_[s] = 0;
        std::queue<u32> queue{ { s } };
        while (queue.size()) {
            u32 v{queue.front()};
            queue.pop();
            for (const Edge& e : g_[v]) if (e.residual > 0) {
                if (label_[e.to] > label_[v] + 1) {
                    label_[e.to] = label_[v] + 1;
                    if (e.to == t) return true;
                    queue.emplace(e.to);
                }
            }
        }
        return false;
    }

    bool admissible(u32 v, const Edge& e) const noexcept {
        return e.residual > 0 and label_[v] + 1 == label_[e.to];
    }

    inline void flow(Edge& e, Cap f) {
        e.residual -= f;
        g_[e.to][e.rev].residual += f;
    }

    Cap dfs(u32 v, u32 t, Cap up) {
        if (v == t) return up;
        Cap res{};
        for (u32& i{cur_[v]} ; i < g_[v].size() ; i++) {
            if (!admissible(v, g_[v][i])) continue;
            Cap f{dfs(g_[v][i].to, t, std::min(g_[v][i].residual, up - res))};
            if (f == 0) continue;
            flow(g_[v][i], f);
            res += f;
            if (res == up) return res;
        }
        return res;
    }

    Cap primalStep(u32 s, u32 t) {
        std::fill(cur_.begin(), cur_.end(), 0u);
        cur_[t] = g_[t].size();
        Cap res{};
        while (true) {
            Cap f{dfs(s, t, std::numeric_limits<Cap>::max())};
            if (f == 0) break;
            res += f;
        }
        return res;
    }

    const Edge& edge(u32 i) const noexcept {
        return g_[edges_[i].first()][edges_[i].second()];
    }
    const Edge& reverse(u32 i) const noexcept {
        const Edge& e{edge(i)};
        return g_[e.to][e.rev];
    }

public:
    Dinic() = default;
    Dinic(u32 n, u32 m = 0u) 
        : n_{n}, m_{m}, g_(n), edges_{}, label_(n), cur_(n) {
        g_.shrink_to_fit();
        label_.shrink_to_fit();
        cur_.shrink_to_fit();
        edges_.reserve(m);
    }

    u32 addEdge(u32 u, u32 v, const Cap& cap) {
        assert(u < size());
        assert(v < size());
        u32 id{static_cast<u32>(g_[u].size())};
        u32 revId{u == v ? id + 1 : static_cast<u32>(g_[v].size())};
        u32 res{static_cast<u32>(edges_.size())};
        edges_.emplace_back(u, id);
        g_[u].emplace_back(v, revId, cap);
        g_[v].emplace_back(u, id, Cap{});
        return res;
    }

    const Cap& flowed(u32 id) const noexcept {
        assert(id < edgeNumber());
        return reverse(id).residual;
    }
    const Cap& residual(u32 id) const noexcept {
        assert(id < edgeNumber());
        return edge(id).residual;
    }
    const Cap& capacity(u32 id) const noexcept {
        assert(id < edgeNumber());
        return edge(id).residual + reverse(id).residual;
    }

    Cap flow(u32 s, u32 t) {
        assert(s < size());
        assert(t < size()); 
        Cap res{};
        while (dualStep(s, t)) {
            res += primalStep(s, t);
        }
        return res;
    }

    std::vector<bool> cut(u32 s) {
        std::vector<bool> res(size());
        res[s] = true;
        std::queue<u32> queue{ { s } };
        while (queue.size()) {
            u32 v{queue.front()};
            queue.pop();
            for (const auto& e : g_[v]) if (e.cap > 0 and !res[e.to]) {
                res[e.to] = true;
                queue.emplace(e.to);
            }
        }
        return res;
    }    
};

} // namespace zawa
#line 5 "3168.test.cpp"

#line 7 "3168.test.cpp"
#include <utility>
#line 9 "3168.test.cpp"

bool adjust(char a, char b) {
    if (a > b) std::swap(a, b);
    if (a == 'a' and b == 'z') return true;
    return (int)(b - a) == 1;
}

int main() {
    using namespace zawa;
    int n, m, k; std::cin >> n >> m >> k;
    std::vector<char> s(n);
    for (auto& c : s) std::cin >> c;
    const int INF{(int)1e9};
    std::vector g(n, std::vector<int>(n, INF));
    for (int i{} ; i < n ; i++) g[i][i] = 0;
    for (int _{} ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        g[u][v] = g[v][u] = 1;
    }
    for (int k{} ; k < n ; k++) {
        for (int i{} ; i < n ; i++) {
            for (int j{} ; j < n ; j++) {
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    Dinic<int> solver(2 * n + 2);
    for (int i{} ; i < n ; i++) {
        solver.addEdge(2 * n, i, 1);
        solver.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i{} ; i < n ; i++) {
        for (int j{i + 1} ; j < n ; j++) {
            if (g[i][j] > k) continue;
            if (!adjust(s[i], s[j])) continue;
            if (s[i] % 2) {
                solver.addEdge(i, n + j, 1);
            }
            else {
                solver.addEdge(j, n + i, 1);
            }
        }
    }
    int ans{solver.flow(2 * n, 2 * n + 1)};
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 4832
final_rank: 3

code_snippet: #line 1 "3168.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/3168"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#include <iostream>
#include <iomanip>

namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
#line 2 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#line 4 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
#include <vector>

namespace zawa {

template <class Cap>
class Dinic {
private:
    static_assert(std::is_signed_v<Cap>, "Cap must be signed");
    static constexpr u32 INVALID{static_cast<u32>(-1)};
    using EdgePointer = std::pair<u32, u32>;
public:
    static constexpr u32 invalid() noexcept {
        return INVALID;
    }
private:
    class ResidualGraph {
    public:
        struct Edge {
            u32 from{}, to{};
            Cap cap{};
            u32 rev{}, id{};
            Edge() = default;
            Edge(u32 from, u32 to, const Cap& cap, u32 rev, u32 id)
                : from{from}, to{to}, cap{cap}, rev{rev}, id{id} {}
            EdgePointer reverseEdgePointer() const {
                return EdgePointer{to, rev};
            }
        }; 
    private:
        usize n_{}, m_{};
        std::vector<std::vector<Edge>> g_{};
    public:
        ResidualGraph() = default;
        ResidualGraph(usize n) : n_{n}, m_{}, g_(n) {
            g_.shrink_to_fit();
        }

        inline usize size() const noexcept {
            return n_;
        }
        inline usize edgeNumber() const noexcept {
            return m_;
        }
        u32 invalidEdgePointer(u32 v) const noexcept {
            return g_[v].size();
        }

        std::vector<Edge>& operator[](usize i) noexcept {
            return g_[i];
        }
        const std::vector<Edge>& operator[](usize i) const noexcept {
            return g_[i];
        }
        Edge& operator[](const EdgePointer& e) noexcept {
            return g_[e.first][e.second];
        }
        const Edge& operator[](const EdgePointer& e) const noexcept {
            return g_[e.first][e.second];
        }

        const Edge& reverseEdge(const EdgePointer& pos) {
            return g_[g_[pos].reverseEdgePointer()];
        }
        
        u32 addEdge(u32 from, u32 to, const Cap& cap, u32 id) {
            u32 i{static_cast<u32>(g_[from].size())};
            u32 j{static_cast<u32>(from == to ? i + 1 : g_[to].size())};
            g_[from].emplace_back(from, to, cap, j, id);
            g_[to].emplace_back(to, from, Cap{}, i, id);
            m_++;
            return i;
        }
        void update(Edge& e, const Cap& flow) {
            assert(e.cap >= flow);
            e.cap -= flow;
            (*this)[e.reverseEdgePointer()].cap += flow;
        }
    };

    using Edge = typename ResidualGraph::Edge;

    ResidualGraph graph_;
    std::vector<u32> label_;
    std::vector<EdgePointer> edges_;

public:
    inline usize size() const noexcept {
        return graph_.size();
    }
    inline usize edgeNumber() const noexcept { 
        return graph_.edgeNumber();
    }
private:

    bool admissible(const Edge& e) {
        return e.cap > 0 and label_[e.from] + 1 == label_[e.to];
    }

    bool dualStep(u32 s, u32 t) {
        std::fill(label_.begin(), label_.end(), invalid());
        label_[s] = 0;
        std::vector<u32> queue;
        queue.reserve(size());
        queue.emplace_back(s);
        for (u32 topQ{} ; topQ < queue.size() ; topQ++) {
            u32 v{queue[topQ]};
            for (const auto& e : graph_[v]) if (e.cap > 0) {
                if (label_[e.to] > label_[v] + 1) {
                    label_[e.to] = label_[v] + 1;
                    queue.emplace_back(e.to);
                }
            }
        }
        return label_[t] < size();
    }

    bool findAdmissiblePath(u32 s, u32 t, std::vector<EdgePointer>& path) {
        std::vector<u32> currentEdge(size());
        currentEdge[t] = graph_.invalidEdgePointer(t);
        u32 v{s};
        while (true) {
            while (currentEdge[v] != graph_.invalidEdgePointer(v)) {
                const Edge& now{graph_[v][currentEdge[v]]};
                if (admissible(now)) {
                    path.emplace_back(v, currentEdge[v]);
                    v = now.to;
                }
                else {
                    currentEdge[v]++;
                }
            }
            if (v == s) return false;
            if (v == t) return true;
            if (v != t) {
                v = path.back().first;
                path.pop_back();
                currentEdge[v]++;
            }
        }
        assert(false);
        return false;
    }

    Cap flow(const std::vector<EdgePointer>& path) {
        auto min{std::min_element(path.begin(), path.end(), [&](const EdgePointer& l, const EdgePointer& r) -> bool {
                return graph_[l].cap < graph_[r].cap;
            })};
        Cap amount{graph_[*min].cap};
        assert(amount > 0);
        for (const auto& pos : path) {
            Edge& e{graph_[pos]};
            graph_.update(e, amount);
        }
        return amount;
    }

    Cap primalStep(u32 s, u32 t) {
        std::vector<EdgePointer> path;
        Cap res{};
        while (findAdmissiblePath(s, t, path)) {
            res += flow(path);
            path.clear();
        }
        return res;
    }

public:

    Dinic() = default;
    // @param m: 辺数をここに入れるとreserveしてくれる
    Dinic(usize n, usize m = usize{}) : graph_{n}, label_(n) {
        label_.shrink_to_fit();
        edges_.reserve(m);
    }

    u32 addEdge(u32 from, u32 to, const Cap& cap, u32 id = invalid()) {
        assert(from < size());
        assert(to < size());
        u32 res{static_cast<u32>(edges_.size())};
        edges_.emplace_back(from, graph_.addEdge(from, to, cap, id));
        return res;
    }

    Cap residual(u32 id) {
        assert(id < edgeNumber());
        return graph_[edges_[id]].cap;
    }

    Cap flowed(u32 id) {
        assert(id < edgeNumber());
        return graph_.reverseEdge(edges_[id]).cap;
    }

    Cap originCap(u32 id) {
        assert(id < edgeNumber());
        EdgePointer e{edges_[id]};
        return graph_[e].cap + graph_.reverseEdge(edges_[id]).cap;
    }

    Cap flow(u32 s, u32 t) {
        assert(s < size());
        assert(t < size());
        Cap res{};
        while (dualStep(s, t)) {
            res += primalStep(s, t);
        }
        return res;
    }
};

} // namespace zawa
#line 5 "3168.test.cpp"

#line 9 "3168.test.cpp"

bool adjust(char a, char b) {
    if (a > b) std::swap(a, b);
    if (a == 'a' and b == 'z') return true;
    return (int)(b - a) == 1;
}

int main() {
    using namespace zawa;
    int n, m, k; std::cin >> n >> m >> k;
    std::vector<char> s(n);
    for (auto& c : s) std::cin >> c;
    const int INF{(int)1e9};
    std::vector g(n, std::vector<int>(n, INF));
    for (int i{} ; i < n ; i++) g[i][i] = 0;
    for (int _{} ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        g[u][v] = g[v][u] = 1;
    }
    for (int k{} ; k < n ; k++) {
        for (int i{} ; i < n ; i++) {
            for (int j{} ; j < n ; j++) {
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    Dinic<int> solver(2 * n + 2);
    for (int i{} ; i < n ; i++) {
        solver.addEdge(2 * n, i, 1);
        solver.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i{} ; i < n ; i++) {
        for (int j{i + 1} ; j < n ; j++) {
            if (g[i][j] > k) continue;
            if (!adjust(s[i], s[j])) continue;
            if (s[i] % 2) {
                solver.addEdge(i, n + j, 1);
            }
            else {
                solver.addEdge(j, n + i, 1);
            }
        }
    }
    int ans{solver.flow(2 * n, 2 * n + 1)};
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 5384
final_rank: 9

code_snippet: #line 1 "3168.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/3168"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#include <iostream>
#include <iomanip>

namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
#line 2 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#line 4 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
#include <vector>

namespace zawa {

template <class Cap>
class Dinic {
private:
    static_assert(std::is_signed_v<Cap>, "Cap must be signed");
    static constexpr u32 INVALID{static_cast<u32>(-1)};
public:
    static constexpr u32 invalid() noexcept {
        return INVALID;
    }
private:
    class ResidualGraph {
    public:
        struct Edge {
            u32 from{}, to{};
            Cap cap{};
            u32 rev{}, id{};
            Edge() = default;
            Edge(u32 from, u32 to, const Cap& cap, u32 rev, u32 id)
                : from{from}, to{to}, cap{cap}, rev{rev}, id{id} {}
        }; 
    private:
        usize n_{}, m_{};
        std::vector<std::vector<Edge>> g_{};
    public:
        ResidualGraph() = default;
        ResidualGraph(usize n) : n_{n}, m_{}, g_(n) {
            g_.shrink_to_fit();
        }

        inline usize size() const noexcept {
            return n_;
        }
        inline usize edgeNumber() const noexcept {
            return m_;
        }

        std::vector<Edge>& operator[](usize i) noexcept {
            assert(i < size());
            return g_[i];
        }
        const std::vector<Edge>& operator[](usize i) const noexcept {
            assert(i < size());
            return g_[i];
        }

        void addEdge(u32 from, u32 to, const Cap& cap, u32 id) {
            u32 i{static_cast<u32>(g_[from].size())};
            u32 j{static_cast<u32>(from == to ? i + 1 : g_[to].size())};
            g_[from].emplace_back(from, to, cap, j, id);
            g_[to].emplace_back(to, from, Cap{}, i, id);
            m_++;
        }
        void update(Edge& e, const Cap& flow) {
            assert(e.cap >= flow);
            e.cap -= flow;
            g_[e.to][e.rev].cap += flow;
        }
        u32 invalidEdgePointer(u32 v) const noexcept {
            return g_[v].size();
        }
    };

    ResidualGraph graph_;
    std::vector<u32> label_;

public:
    using Edge = typename ResidualGraph::Edge;
    inline usize size() const noexcept {
        return graph_.size();
    }
private:

    bool admissible(const Edge& e) {
        return e.cap > 0 and label_[e.from] + 1 == label_[e.to];
    }

    bool dualStep(u32 s, u32 t) {
        std::fill(label_.begin(), label_.end(), invalid());
        label_[s] = 0;
        std::vector<u32> queue;
        queue.reserve(size());
        queue.emplace_back(s);
        for (u32 topQ{} ; topQ < queue.size() ; topQ++) {
            u32 v{queue[topQ]};
            for (const auto& e : graph_[v]) if (e.cap > 0) {
                if (label_[e.to] > label_[v] + 1) {
                    label_[e.to] = label_[v] + 1;
                    queue.emplace_back(e.to);
                }
            }
        }
        return label_[t] < size();
    }

    using EdgePointer = std::pair<u32, u32>;

    bool findAdmissiblePath(u32 s, u32 t, std::vector<EdgePointer>& path) {
        std::vector<u32> currentEdge(size());
        currentEdge[t] = graph_.invalidEdgePointer(t);
        u32 v{s};
        while (true) {
            while (currentEdge[v] != graph_.invalidEdgePointer(v)) {
                const Edge& now{graph_[v][currentEdge[v]]};
                if (admissible(now)) {
                    path.emplace_back(v, currentEdge[v]);
                    v = now.to;
                }
                else {
                    currentEdge[v]++;
                }
            }
            if (v == s) return false;
            if (v == t) return true;
            if (v != t) {
                v = path.back().first;
                path.pop_back();
                currentEdge[v]++;
            }
        }
        assert(false);
        return false;
    }

    Cap flow(const std::vector<EdgePointer>& path) {
        auto min{std::min_element(path.begin(), path.end(), [&](const EdgePointer& l, const EdgePointer& r) -> bool {
                return graph_[l.first][l.second].cap < graph_[r.first][r.second].cap;
            })};
        Cap amount{graph_[min->first][min->second].cap};
        assert(amount > 0);
        for (const auto& [x, y] : path) {
            Edge& e{graph_[x][y]};
            graph_.update(e, amount);
        }
        return amount;
    }

    Cap primalStep(u32 s, u32 t) {
        std::vector<EdgePointer> path;
        Cap res{};
        while (findAdmissiblePath(s, t, path)) {
            res += flow(path);
            path.clear();
        }
        return res;
    }

public:

    Dinic() = default;
    Dinic(usize n) : graph_{n}, label_(n) {
        label_.shrink_to_fit();
    }

    void addEdge(u32 from, u32 to, const Cap& cap, u32 id = invalid()) {
        assert(from < size());
        assert(to < size());
        graph_.addEdge(from, to, cap, id);
    }

    Cap flow(u32 s, u32 t) {
        assert(s < size());
        assert(t < size());
        Cap res{};
        while (dualStep(s, t)) {
            res += primalStep(s, t);
        }
        return res;
    }
};

} // namespace zawa
#line 5 "3168.test.cpp"

#line 9 "3168.test.cpp"

bool adjust(char a, char b) {
    if (a > b) std::swap(a, b);
    if (a == 'a' and b == 'z') return true;
    return (int)(b - a) == 1;
}

int main() {
    using namespace zawa;
    int n, m, k; std::cin >> n >> m >> k;
    std::vector<char> s(n);
    for (auto& c : s) std::cin >> c;
    const int INF{(int)1e9};
    std::vector g(n, std::vector<int>(n, INF));
    for (int i{} ; i < n ; i++) g[i][i] = 0;
    for (int _{} ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        g[u][v] = g[v][u] = 1;
    }
    for (int k{} ; k < n ; k++) {
        for (int i{} ; i < n ; i++) {
            for (int j{} ; j < n ; j++) {
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    Dinic<int> solver(2 * n + 2);
    for (int i{} ; i < n ; i++) {
        solver.addEdge(2 * n, i, 1);
        solver.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i{} ; i < n ; i++) {
        for (int j{i + 1} ; j < n ; j++) {
            if (g[i][j] > k) continue;
            if (!adjust(s[i], s[j])) continue;
            if (s[i] % 2) {
                solver.addEdge(i, n + j, 1);
            }
            else {
                solver.addEdge(j, n + i, 1);
            }
        }
    }
    int ans{solver.flow(2 * n, 2 * n + 1)};
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 5224
final_rank: 7

code_snippet: #line 1 "3168.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/3168"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#include <iostream>
#include <iomanip>

namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
#line 2 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#line 4 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
#include <vector>

// #include <iostream>

namespace zawa {

template <class Cap>
class Dinic {
private:
    static_assert(std::is_signed_v<Cap>, "Cap must be signed");
    static constexpr u32 INVALID{static_cast<u32>(-1)};
public:
    static constexpr u32 invalid() noexcept {
        return INVALID;
    }
private:
    class ResidualGraph {
    public:
        struct Edge {
            u32 from{}, to{};
            Cap cap{};
            u32 rev{}, id{};
            Edge() = default;
            Edge(u32 from, u32 to, const Cap& cap, u32 rev, u32 id)
                : from{from}, to{to}, cap{cap}, rev{rev}, id{id} {}
        }; 
    private:
        usize n_{}, m_{};
        std::vector<std::vector<Edge>> g_{};
    public:
        ResidualGraph() = default;
        ResidualGraph(usize n) : n_{n}, m_{}, g_(n) {
            g_.shrink_to_fit();
        }

        inline usize size() const noexcept {
            return n_;
        }
        inline usize edgeNumber() const noexcept {
            return m_;
        }

        std::vector<Edge>& operator[](usize i) noexcept {
            assert(i < size());
            return g_[i];
        }
        const std::vector<Edge>& operator[](usize i) const noexcept {
            assert(i < size());
            return g_[i];
        }

        void addEdge(u32 from, u32 to, const Cap& cap, u32 id) {
            u32 i{static_cast<u32>(g_[from].size())};
            u32 j{static_cast<u32>(from == to ? i + 1 : g_[to].size())};
            g_[from].emplace_back(from, to, cap, j, id);
            g_[to].emplace_back(to, from, Cap{}, i, id);
            m_++;
        }
        void update(Edge& e, const Cap& flow) {
            assert(e.cap >= flow);
            e.cap -= flow;
            g_[e.to][e.rev].cap += flow;
        }
        u32 invalidEdgePointer(u32 v) const noexcept {
            return g_[v].size();
        }
    };

    ResidualGraph graph_;
    std::vector<u32> label_;

public:
    using Edge = typename ResidualGraph::Edge;
    inline usize size() const noexcept {
        return graph_.size();
    }
private:

    bool admissible(const Edge& e) {
        return e.cap > 0 and label_[e.from] + 1 == label_[e.to];
    }

    bool dualStep(u32 s, u32 t) {
        std::fill(label_.begin(), label_.end(), invalid());
        label_[s] = 0;
        std::vector<u32> queue;
        queue.reserve(size());
        queue.emplace_back(s);
        for (u32 topQ{} ; topQ < queue.size() ; topQ++) {
            u32 v{queue[topQ]};
            for (const auto& e : graph_[v]) if (e.cap > 0) {
                if (label_[e.to] > label_[v] + 1) {
                    label_[e.to] = label_[v] + 1;
                    queue.emplace_back(e.to);
                }
            }
        }
        return label_[t] < size();
    }

    using EdgePointer = std::pair<u32, u32>;

    bool findAdmissiblePath(u32 s, u32 t, std::vector<EdgePointer>& path) {
        std::vector<u32> currentEdge(size());
        currentEdge[t] = graph_.invalidEdgePointer(t);
        u32 v{s};
        while (true) {
            // for (auto [x, y] : path) {
            //     std::cout << '(' << x << ',' << y << ',' << graph_[x][y].cap << ')' << ' ';
            // }
            // std::cout << std::endl;
            while (currentEdge[v] != graph_.invalidEdgePointer(v)) {
                const Edge& now{graph_[v][currentEdge[v]]};
                if (admissible(now)) {
                    // std::cout << "find edge " << '(' << v << ',' << currentEdge[v] << ',' << now.cap << ')' << std::endl;
                    path.emplace_back(v, currentEdge[v]);
                    v = now.to;
                    // std::cout << "v become " << v << std::endl;
                }
                else {
                    currentEdge[v]++;
                }
            }
            if (v == s) return false;
            if (v == t) return true;
            if (v != t) {
                // std::cout << "v rollback " << std::endl;
                v = path.back().first;
                // std::cout << "v become " << v << std::endl;
                path.pop_back();
                currentEdge[v]++;
            }
        }
        assert(false);
        return false;
    }

    Cap flow(const std::vector<EdgePointer>& path) {
        // std::cout << "flowing!!!" << std::endl;
        // for (auto [x, y] : path) {
        //     std::cout << '(' << x << ',' << y << ',' << graph_[x][y].cap << ')' << ' ';
        // }
        // std::cout << std::endl;
        auto min{std::min_element(path.begin(), path.end(), [&](const EdgePointer& l, const EdgePointer& r) -> bool {
                return graph_[l.first][l.second].cap < graph_[r.first][r.second].cap;
            })};
        Cap amount{graph_[min->first][min->second].cap};
        assert(amount > 0);
        for (const auto& [x, y] : path) {
            Edge& e{graph_[x][y]};
            graph_.update(e, amount);
        }
        return amount;
    }

    Cap primalStep(u32 s, u32 t) {
        std::vector<EdgePointer> path;
        Cap res{};
        while (findAdmissiblePath(s, t, path)) {
            res += flow(path);
            path.clear();
        }
        return res;
    }

public:

    Dinic() = default;
    Dinic(usize n) : graph_{n}, label_(n) {
        label_.shrink_to_fit();
    }

    void addEdge(u32 from, u32 to, const Cap& cap, u32 id = invalid()) {
        assert(from < size());
        assert(to < size());
        graph_.addEdge(from, to, cap, id);
    }

    Cap flow(u32 s, u32 t) {
        assert(s < size());
        assert(t < size());
        Cap res{};
        while (dualStep(s, t)) {
            res += primalStep(s, t);
        }
        return res;
    }
};

} // namespace zawa
#line 5 "3168.test.cpp"

#line 9 "3168.test.cpp"

bool adjust(char a, char b) {
    if (a > b) std::swap(a, b);
    if (a == 'a' and b == 'z') return true;
    return (int)(b - a) == 1;
}

int main() {
    using namespace zawa;
    int n, m, k; std::cin >> n >> m >> k;
    std::vector<char> s(n);
    for (auto& c : s) std::cin >> c;
    const int INF{(int)1e9};
    std::vector g(n, std::vector<int>(n, INF));
    for (int i{} ; i < n ; i++) g[i][i] = 0;
    for (int _{} ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        g[u][v] = g[v][u] = 1;
    }
    for (int k{} ; k < n ; k++) {
        for (int i{} ; i < n ; i++) {
            for (int j{} ; j < n ; j++) {
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    Dinic<int> solver(2 * n + 2);
    for (int i{} ; i < n ; i++) {
        solver.addEdge(2 * n, i, 1);
        solver.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i{} ; i < n ; i++) {
        for (int j{i + 1} ; j < n ; j++) {
            if (g[i][j] > k) continue;
            if (!adjust(s[i], s[j])) continue;
            if (s[i] % 2) {
                solver.addEdge(i, n + j, 1);
            }
            else {
                solver.addEdge(j, n + i, 1);
            }
        }
    }
    int ans{solver.flow(2 * n, 2 * n + 1)};
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 5224
final_rank: 7

code_snippet: #line 1 "3168.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/3168"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#line 2 "/home/zawatin/compro/cp-documentation/Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "/home/zawatin/compro/cp-documentation/Src/Template/IOSetting.hpp"

#include <iostream>
#include <iomanip>

namespace zawa {

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

void SetPrecision(u32 dig) {
    std::cout << std::fixed << std::setprecision(dig);
}

} // namespace zawa
#line 2 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#line 4 "/home/zawatin/compro/cp-documentation/Src/Graph/Flow/Dinic.hpp"

#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
#include <vector>

// #include <iostream>

namespace zawa {

template <class Cap>
class Dinic {
private:
    static_assert(std::is_signed_v<Cap>, "Cap must be signed");
    static constexpr u32 INVALID{static_cast<u32>(-1)};
public:
    static constexpr u32 invalid() noexcept {
        return INVALID;
    }
private:
    class ResidualGraph {
    public:
        struct Edge {
            u32 from{}, to{};
            Cap cap{};
            u32 rev{}, id{};
            Edge() = default;
            Edge(u32 from, u32 to, const Cap& cap, u32 rev, u32 id)
                : from{from}, to{to}, cap{cap}, rev{rev}, id{id} {}
        }; 
    private:
        usize n_{}, m_{};
        std::vector<std::vector<Edge>> g_{};
    public:
        ResidualGraph() = default;
        ResidualGraph(usize n) : n_{n}, m_{}, g_(n) {
            g_.shrink_to_fit();
        }

        inline usize size() const noexcept {
            return n_;
        }
        inline usize edgeNumber() const noexcept {
            return m_;
        }

        std::vector<Edge>& operator[](usize i) noexcept {
            assert(i < size());
            return g_[i];
        }
        const std::vector<Edge>& operator[](usize i) const noexcept {
            assert(i < size());
            return g_[i];
        }

        void addEdge(u32 from, u32 to, const Cap& cap, u32 id) {
            u32 i{static_cast<u32>(g_[from].size())};
            u32 j{static_cast<u32>(from == to ? i + 1 : g_[to].size())};
            g_[from].emplace_back(from, to, cap, j, id);
            g_[to].emplace_back(to, from, Cap{}, j, id);
            m_++;
        }
        void update(Edge& e, const Cap& flow) {
            assert(e.cap >= flow);
            e.cap -= flow;
            g_[e.to][e.rev].cap += flow;
        }
        u32 invalidEdgePointer(u32 v) const noexcept {
            return g_[v].size();
        }
    };

    ResidualGraph graph_;
    std::vector<u32> label_;

public:
    using Edge = typename ResidualGraph::Edge;
    inline usize size() const noexcept {
        return graph_.size();
    }
private:

    bool admissible(const Edge& e) {
        return e.cap > 0 and label_[e.from] + 1 == label_[e.to];
    }

    bool dualStep(u32 s, u32 t) {
        std::fill(label_.begin(), label_.end(), invalid());
        label_[s] = 0;
        std::vector<u32> queue;
        queue.reserve(size());
        queue.emplace_back(s);
        for (u32 topQ{} ; topQ < queue.size() ; topQ++) {
            u32 v{queue[topQ]};
            for (const auto& e : graph_[v]) if (e.cap > 0) {
                if (label_[e.to] > label_[v] + 1) {
                    label_[e.to] = label_[v] + 1;
                    queue.emplace_back(e.to);
                }
            }
        }
        return label_[t] < size();
    }

    using EdgePointer = std::pair<u32, u32>;

    bool findAdmissiblePath(u32 s, u32 t, std::vector<EdgePointer>& path) {
        std::vector<u32> currentEdge(size());
        currentEdge[t] = graph_.invalidEdgePointer(t);
        u32 v{s};
        while (true) {
            // for (auto [x, y] : path) {
            //     std::cout << '(' << x << ',' << y << ',' << graph_[x][y].cap << ')' << ' ';
            // }
            // std::cout << std::endl;
            while (currentEdge[v] != graph_.invalidEdgePointer(v)) {
                const Edge& now{graph_[v][currentEdge[v]]};
                if (admissible(now)) {
                    // std::cout << "find edge " << '(' << v << ',' << currentEdge[v] << ',' << now.cap << ')' << std::endl;
                    path.emplace_back(v, currentEdge[v]);
                    v = now.to;
                    // std::cout << "v become " << v << std::endl;
                }
                else {
                    currentEdge[v]++;
                }
            }
            if (v == s) return false;
            if (v == t) return true;
            if (v != t) {
                // std::cout << "v rollback " << std::endl;
                v = path.back().first;
                // std::cout << "v become " << v << std::endl;
                path.pop_back();
                currentEdge[v]++;
            }
        }
        assert(false);
        return false;
    }

    Cap flow(const std::vector<EdgePointer>& path) {
        // std::cout << "flowing!!!" << std::endl;
        // for (auto [x, y] : path) {
        //     std::cout << '(' << x << ',' << y << ',' << graph_[x][y].cap << ')' << ' ';
        // }
        // std::cout << std::endl;
        auto min{std::min_element(path.begin(), path.end(), [&](const EdgePointer& l, const EdgePointer& r) -> bool {
                return graph_[l.first][l.second].cap < graph_[r.first][r.second].cap;
            })};
        Cap amount{graph_[min->first][min->second].cap};
        assert(amount > 0);
        for (const auto& [x, y] : path) {
            Edge& e{graph_[x][y]};
            graph_.update(e, amount);
        }
        return amount;
    }

    Cap primalStep(u32 s, u32 t) {
        std::vector<EdgePointer> path;
        Cap res{};
        while (findAdmissiblePath(s, t, path)) {
            res += flow(path);
            path.clear();
        }
        return res;
    }

public:

    Dinic() = default;
    Dinic(usize n) : graph_{n}, label_(n) {
        label_.shrink_to_fit();
    }

    void addEdge(u32 from, u32 to, const Cap& cap, u32 id = invalid()) {
        assert(from < size());
        assert(to < size());
        graph_.addEdge(from, to, cap, id);
    }

    Cap flow(u32 s, u32 t) {
        assert(s < size());
        assert(t < size());
        Cap res{};
        while (dualStep(s, t)) {
            res += primalStep(s, t);
        }
        return res;
    }
};

} // namespace zawa
#line 5 "3168.test.cpp"

#line 9 "3168.test.cpp"

bool adjust(char a, char b) {
    if (a > b) std::swap(a, b);
    if (a == 'a' and b == 'z') return true;
    return (int)(b - a) == 1;
}

int main() {
    using namespace zawa;
    int n, m, k; std::cin >> n >> m >> k;
    std::vector<char> s(n);
    for (auto& c : s) std::cin >> c;
    const int INF{(int)1e9};
    std::vector g(n, std::vector<int>(n, INF));
    for (int i{} ; i < n ; i++) g[i][i] = 0;
    for (int _{} ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        g[u][v] = g[v][u] = 1;
    }
    for (int k{} ; k < n ; k++) {
        for (int i{} ; i < n ; i++) {
            for (int j{} ; j < n ; j++) {
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    Dinic<int> solver(2 * n + 2);
    for (int i{} ; i < n ; i++) {
        solver.addEdge(2 * n, i, 1);
        solver.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i{} ; i < n ; i++) {
        for (int j{i + 1} ; j < n ; j++) {
            if (g[i][j] > k) continue;
            if (!adjust(s[i], s[j])) continue;
            if (s[i] % 2) {
                solver.addEdge(i, n + j, 1);
            }
            else {
                solver.addEdge(j, n + i, 1);
            }
        }
    }
    int ans{solver.flow(2 * n, 2 * n + 1)};
    std::cout << ans << '\n';
}
accuracy: 0.6909090909090909
time_ms: 20
memory_kb: 5228
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int,int> P;
typedef vector<ll> vec;
typedef vector<vec> Graph;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

//https://github.com/atcoder/ac-library/tree/master/atcoder
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1

#include <vector>

namespace atcoder {

namespace internal {

template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_QUEUE_HPP

#ifndef ATCODER_MAXFLOW_HPP
#define ATCODER_MAXFLOW_HPP 1

#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>


namespace atcoder {

template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    explicit mf_graph(int n) : _n(n), g(n) {}

    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        int from_id = int(g[from].size());
        int to_id = int(g[to].size());
        if (from == to) to_id++;
        g[from].push_back(_edge{to, to_id, cap});
        g[to].push_back(_edge{from, from_id, 0});
        return m;
    }

    struct edge {
        int from, to;
        Cap cap, flow;
    };

    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }

    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
        assert(s != t);

        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;

        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) return res;
            }
            level[v] = _n;
            return res;
        };

        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            Cap f = dfs(dfs, t, flow_limit - flow);
            if (!f) break;
            flow += f;
        }
        return flow;
    }

    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }

  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};

}  // namespace atcoder

#endif  // ATCODER_MAXFLOW_HPP

using namespace atcoder;
 

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    vector<char> c(n);
    rep(i,n)cin>>c[i];
    mf_graph<ll> g(n*2+2);
    Graph G(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,n){
        vec dist(n,-1);
        dist[i]=0;
        queue<ll> que;
        que.push(i);
        while(que.size()){
            ll x=que.front();
            que.pop();
            for(ll nx:G[x]){
                if(dist[nx]>=0)continue;
                que.push(nx);
                dist[nx]=dist[x]+1;
            }
        }
        rep(j,n){
            if(dist[j]==-1)continue;
            if(dist[j]<=k){
                ll x=c[i]-'a';
                ll y=c[j]-'a';
                ll sub=abs(x-y);
                if(sub==1||sub==25){
                    if(x%2==0)g.add_edge(2+i,2+n+j,1e6);
                    else g.add_edge(2+j,2+i+n,1e6);
                }
            }
        }
    }
    rep(i,n){
        g.add_edge(0,2+i,1);
        g.add_edge(2+n+i,1,1);
    }
    ll ans=g.flow(0,1);
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6940
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

// テンプレート引数: 距離の型TとT型の無効値(十分大きな値)INF
// 引数: Nは頂点数、次に辺の情報(u, v, cost)
// directedをtrueにすると有向辺として扱う(u -> v)向き
// INFはオーバーフロー注意！！(2倍してもオーバーフローしない値である必要がある)
template <class T, T INF>
vector<vector<T>> WF(int N, vector<tuple<int, int, T>> E, bool directed) {
    vector G(N, vector(N, INF));
    for (int i = 0 ; i < N ; i++) G[i][i] = 0;
    for (auto [u, v, c] : E) {
        G[u][v] = min(G[u][v], c);
        if (!directed) G[v][u] = min(G[v][u], c);
    }
    for (int k = 0 ; k < N ; k++) {
        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < N ; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    return G;
}


// O(E V^2)
// O(E \min(E^{1/2}, V^{2/3})) if caps are constant
// template param Flow: 流量の型
// template param directed: 有向ならtrue
template<typename Flow,bool directed>
struct Dinic{
    // @member dst: 辺の向かう先
    // @member cap: 容量
    // @member rev: 逆辺の「識別番号」
    // @brief: 流量は管理していないっぽいので、流量が欲しい時は追加時の容量と現在の容量から流量を計算する必要がある。
    struct Edge {
        int dst;
        Flow cap;
        int rev;
        Edge(int dst,Flow cap,int rev):dst(dst),cap(cap),rev(rev){}
    };

    vector< vector<Edge> > G;
    vector<int> level,iter;

    // @param n: 頂点数
    Dinic(int n):G(n),level(n),iter(n){}

    // @brief srcからdstへ容量capの辺を追加する
    // @param src: 始点
    // @param dst: 終点
    // @param cap: 容量
    // @response: 追加した辺の識別番号(多分)
    int add_edge(int src,int dst,Flow cap){
        int e=G[src].size();
        int r=(src==dst?e+1:G[dst].size());
        G[src].emplace_back(dst,cap,r);
        G[dst].emplace_back(src,directed?0:cap,e);
        return e;
    }

    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int> que;
        level[s]=0;
        que.emplace(s);
        while(!que.empty()){
            int v=que.front();que.pop();
            for(Edge &e : G[v]) {
                if(e.cap>0 and level[e.dst]<0){
                    level[e.dst]=level[v]+1;
                    que.emplace(e.dst);
                }
            }
        }
    }

    Flow dfs(int v,int t,Flow f){
        if(v==t) return f;
        for(int &i=iter[v];i<(int)G[v].size();i++){
            Edge &e=G[v][i];
            if(e.cap>0 and level[v]<level[e.dst]){
                Flow d=dfs(e.dst,t,min(f,e.cap));
                if(d==0) continue;
                e.cap-=d;
                G[e.dst][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }

    // @brief: sからtへの最大フローを求める
    Flow flow(int s,int t){
        return flow(s,t,numeric_limits<Flow>::max()/2);
    }

    // @brief: sからtへの流量制限limの最大フローを流す(多分)
    Flow flow(int s,int t,Flow lim){
        Flow fl=0;
        while(1){
            bfs(s);
            if(level[t]<0 or lim==0) break;
            fill(iter.begin(),iter.end(),0);

            while(1){
                Flow f=dfs(s,t,lim);
                if(f==0) break;
                fl+=f;
                lim-=f;
            }
        }
        return fl;
    }

    // よくわからない
    Flow cut(int s,int t,int x,int a){
        static_assert(directed, "must be directed");
        auto &e=G[x][a];
        int y=e.dst;
        Flow cr=G[y][e.rev].cap;
        if(cr==0) return e.cap=0;
        e.cap=G[y][e.rev].cap=0;
        Flow cap=cr-flow(x,y,cr);
        if(x!=s and cap!=0) flow(x,s,cap);
        if(t!=y and cap!=0) flow(t,y,cap);
        return cap;
    }

    // @brief: 頂点xのa番目の辺に流量fを追加してs -> tへフローを流す
    // @condition: 頂点xにa個以上の辺が存在する
    // @param s: フローのsource
    // @param t: フローのsink
    // @param x: 流量を追加したい辺の始点がある頂点
    // @param a: 流量を追加した辺の識別番号
    // @param f: 追加したい流量
    Flow link(int s,int t,int x,int a,Flow f){
        auto &e=G[x][a];
        e.cap+=f;
        return flow(s,t,f);
    }
};

vector<int> BipJudge(vector<vector<int>> G) {
    size_t N = G.size();
    vector<int> col(N, -1);

    auto dfs = [&](auto dfs, int v, int c) -> bool {
        col[v] = c;
        for (auto x : G[v]) {
            if (col[x] == c) return false;
            if (col[x] == -1 and !dfs(dfs, x, 1 - c)) return false;
        }
        return true;
    };

    bool ok = true;
    for (size_t i = 0 ; i < N ; i++) {
        ok &= (col[i] != -1 or dfs(dfs, i, 0));
    }

    if (ok) return col;
    else return vector<int>(N, -1);
}

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<char> C(N);
    for (auto& c : C) cin >> c;
    
    vector<tuple<int, int, int>> E(M);
    for (auto& [u, v, c] : E) {
        cin >> u >> v;
        u--; v--;
        c = 1;
    }

    auto G = WF<int, (int)1e9>(N, E, false);

    vector<vector<int>> Ebi(N); 
    for (int i = 0 ; i < N ; i++) {
        for (int j = 0 ; j < N ; j++) {
            if (G[i][j] > K) continue;
            int s = (C[i] - C[j] + 26) % 26;
            if (s == 1 or s == 25) {
                Ebi[i].push_back(j);
            }
        }
    }

    vector<int> col = BipJudge(Ebi);

    Dinic<int, true> din(N + 2);
    for (int i = 0 ; i < N ; i++) {
        if (col[i] == 0) {
            din.add_edge(N, i, 1);
            for (auto x : Ebi[i]) din.add_edge(i, x, 1);
        }
        else {
            din.add_edge(i, N + 1, 1);
        }
    }

    int ans = din.flow(N, N + 1);

    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5172
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

// テンプレート引数: 距離の型TとT型の無効値(十分大きな値)INF
// 引数: Nは頂点数、次に辺の情報(u, v, cost)
// directedをtrueにすると有向辺として扱う(u -> v)向き
// INFはオーバーフロー注意！！(2倍してもオーバーフローしない値である必要がある)
template <class T, T INF>
vector<vector<T>> WF(int N, vector<tuple<int, int, T>> E, bool directed) {
    vector G(N, vector(N, INF));
    for (int i = 0 ; i < N ; i++) G[i][i] = 0;
    for (auto [u, v, c] : E) {
        G[u][v] = min(G[u][v], c);
        if (!directed) G[v][u] = min(G[v][u], c);
    }
    for (int k = 0 ; k < N ; k++) {
        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < N ; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    return G;
}

// O(E V^2)
// O(E \min(E^{1/2}, V^{2/3})) if caps are constant
template<typename Flow,bool directed>
struct Dinic{
    struct Edge {
        int dst;
        Flow cap;
        int rev;
        Edge(int dst,Flow cap,int rev):dst(dst),cap(cap),rev(rev){}
    };

    vector< vector<Edge> > G;
    vector<int> level,iter;

    Dinic(int n):G(n),level(n),iter(n){}

    int add_edge(int src,int dst,Flow cap){
        int e=G[src].size();
        int r=(src==dst?e+1:G[dst].size());
        G[src].emplace_back(dst,cap,r);
        G[dst].emplace_back(src,directed?0:cap,e);
        return e;
    }

    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int> que;
        level[s]=0;
        que.emplace(s);
        while(!que.empty()){
            int v=que.front();que.pop();
            for(Edge &e : G[v]) {
                if(e.cap>0 and level[e.dst]<0){
                    level[e.dst]=level[v]+1;
                    que.emplace(e.dst);
                }
            }
        }
    }

    Flow dfs(int v,int t,Flow f){
        if(v==t) return f;
        for(int &i=iter[v];i<(int)G[v].size();i++){
            Edge &e=G[v][i];
            if(e.cap>0 and level[v]<level[e.dst]){
                Flow d=dfs(e.dst,t,min(f,e.cap));
                if(d==0) continue;
                e.cap-=d;
                G[e.dst][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }

    Flow flow(int s,int t,Flow lim){
        Flow fl=0;
        while(1){
            bfs(s);
            if(level[t]<0 or lim==0) break;
            fill(iter.begin(),iter.end(),0);

            while(1){
                Flow f=dfs(s,t,lim);
                if(f==0) break;
                fl+=f;
                lim-=f;
            }
        }
        return fl;
    }

    Flow flow(int s,int t){
        return flow(s,t,numeric_limits<Flow>::max()/2);
    }

    Flow cut(int s,int t,int x,int a){
        static_assert(directed, "must be directed");
        auto &e=G[x][a];
        int y=e.dst;
        Flow cr=G[y][e.rev].cap;
        if(cr==0) return e.cap=0;
        e.cap=G[y][e.rev].cap=0;
        Flow cap=cr-flow(x,y,cr);
        if(x!=s and cap!=0) flow(x,s,cap);
        if(t!=y and cap!=0) flow(t,y,cap);
        return cap;
    }

    Flow link(int s,int t,int x,int a,Flow f){
        auto &e=G[x][a];
        e.cap+=f;
        return flow(s,t,f);
    }
};

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<char> C(N);
    for (auto& c : C) cin >> c;
    
    vector<tuple<int, int, int>> E(M);
    for (auto& [u, v, c] : E) {
        cin >> u >> v;
        u--; v--;
        c = 1;
    }

    auto G = WF<int, (int)1e9>(N, E, false);

    vector<vector<int>> Ebi(N); 
    for (int i = 0 ; i < N ; i++) {
        for (int j = 0 ; j < N ; j++) {
            if (G[i][j] > K) continue;
            int s = (C[i] - C[j] + 26) % 26;
            if (s == 1 or s == 25) {
                Ebi[i].push_back(j);
            }
        }
    }

    vector<int> col(N, -1);
    auto dfs = [&](auto dfs, int v, int c) -> void {
        col[v] = c;
        for (auto x : Ebi[v]) {
            if (col[x] == -1) dfs(dfs, x, 1 - c);
        }
    };

    for (int i = 0 ; i < N ; i++) {
        if (col[i] == -1) dfs(dfs, i, 0);
    }

    Dinic<int, true> din(N + 2);
    for (int i = 0 ; i < N ; i++) {
        if (col[i] == 0) {
            din.add_edge(N, i, 1);
            for (auto x : Ebi[i]) din.add_edge(i, x, 1);
        }
        else {
            din.add_edge(i, N + 1, 1);
        }
    }

    int ans = din.flow(N, N + 1);

    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5152
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
// O(E V^2)
// O(E \min(E^{1/2}, V^{2/3})) if caps are constant
template<typename Flow,bool directed>
struct Dinic{
  struct Edge {
    int dst;
    Flow cap;
    int rev;
    Edge(int dst,Flow cap,int rev):dst(dst),cap(cap),rev(rev){}
  };

  vector< vector<Edge> > G;
  vector<int> level,iter;

  Dinic(int n):G(n),level(n),iter(n){}

  int add_edge(int src,int dst,Flow cap){
    int e=G[src].size();
    int r=(src==dst?e+1:G[dst].size());
    G[src].emplace_back(dst,cap,r);
    G[dst].emplace_back(src,directed?0:cap,e);
    return e;
  }

  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.emplace(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(Edge &e : G[v]) {
        if(e.cap>0 and level[e.dst]<0){
          level[e.dst]=level[v]+1;
          que.emplace(e.dst);
        }
      }
    }
  }

  Flow dfs(int v,int t,Flow f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      Edge &e=G[v][i];
      if(e.cap>0 and level[v]<level[e.dst]){
        Flow d=dfs(e.dst,t,min(f,e.cap));
        if(d==0) continue;
        e.cap-=d;
        G[e.dst][e.rev].cap+=d;
        return d;
      }
    }
    return 0;
  }

  Flow flow(int s,int t,Flow lim){
    Flow fl=0;
    while(1){
      bfs(s);
      if(level[t]<0 or lim==0) break;
      fill(iter.begin(),iter.end(),0);

      while(1){
        Flow f=dfs(s,t,lim);
        if(f==0) break;
        fl+=f;
        lim-=f;
      }
    }
    return fl;
  }

  Flow flow(int s,int t){
    return flow(s,t,numeric_limits<Flow>::max()/2);
  }

  Flow cut(int s,int t,int x,int a){
    static_assert(directed, "must be directed");
    auto &e=G[x][a];
    int y=e.dst;
    Flow cr=G[y][e.rev].cap;
    if(cr==0) return e.cap=0;
    e.cap=G[y][e.rev].cap=0;
    Flow cap=cr-flow(x,y,cr);
    if(x!=s and cap!=0) flow(x,s,cap);
    if(t!=y and cap!=0) flow(t,y,cap);
    return cap;
  }

  Flow link(int s,int t,int x,int a,Flow f){
    auto &e=G[x][a];
    e.cap+=f;
    return flow(s,t,f);
  }
};

const int INF = (int)1e9;

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> C(N);
    for (auto& c : C) {
        char op; cin >> op;
        c = (int)op;
    }
    for (auto& c : C) c %= 26;

    vector G(N, vector(N, INF));
    for (int i = 0 ; i < N ; i++) G[i][i] = 0;

    for (int _ = 0 ; _ < M ; _++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u][v] = G[v][u] = 1;
    }

    for (int k = 0 ; k < N ; k++) {
        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < N ; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    vector<vector<int>> Ebi(N);

    for (int i = 0 ; i < N ; i++) {
        for (int j = i + 1 ; j < N ; j++) {
            if (G[i][j] > K) continue;
            int score = (C[i] - C[j] + 26) % 26;
            if (score == 1 or score == 25) {
                Ebi[i].push_back(j);
                Ebi[j].push_back(i);
            }
        }
    }


    vector<int> id(N, -1);
    int size = 0;
    
    auto dfsid = [&](auto dfsid, int v) -> void {
        id[v] = size;
        for (auto x : Ebi[v]) if (id[x] == -1) {
            dfsid(dfsid, x);
        }
    };

    for (int i = 0 ; i < N ; i++) {
        if (id[i] == -1) {
            dfsid(dfsid, i);
            size++;
        }
    }

    vector<int> col(N, -1); 

    auto dfscol = [&](auto dfscol, int v, int c) -> void {
        col[v] = c;
        for (auto x : Ebi[v]) {
            if (col[x] != -1) {
                assert(col[x] == 1 - c);
            }
            else {
                dfscol(dfscol, x, 1 - c);
            }
        }
    };

    for (int i = 0 ; i < N ; i++) {
        if (col[i] == -1) {
            dfscol(dfscol, i, 0);
        }
    }

    Dinic<int, true> din(N + 2);
    vector<int> zero(size), one(size);
    for (int i = 0 ; i < N ; i++) {
        if (col[i] == 0) {
            din.add_edge(N, i, 1);
            for (auto x : Ebi[i]) {
                din.add_edge(i, x, 1);
            }
            zero[id[i]]++;
        }
        else {
            din.add_edge(i, N + 1, 1);
            one[id[i]]++;
        }
    }

    
    int ans = 0;
    for (int i = 0 ; i < size ; i++) {
        ans += min(zero[i], one[i]);
    }

    int f = din.flow(N, N + 1);

    cout << f << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5136
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef long long lint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef char chr;
typedef string str;

#define REP(i, n) for (int i=0;i<(int)n;i++)
#define ALL(x) x.begin() x.begin()
#define SEP " "
#define YES cout << "Yes" << endl
#define NO cout << "NO" << endl
#define OUT(x) cout << x << endl
#define OUTF(x) cout << fixed << setprecision(10) << x << endl
#define SIZE(v) v.size()
#define PB push_back
#define MP make_pair
#define MT make_typle

const double pi = 3.141592653589793238;

const int large_a = 65;
const int small_a = 97;

const int INF = 2147483647;
const int INT_INF = 2147483647;

const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};

template<class T> inline void print_vec(const vector<T>& v) {
	int last = SIZE(v);
	REP(i, last) {
		cout << v[i];
		if(i != last-1) cout << SEP;
	}
	cout << endl;
}

int main() {
	int n,m,k;
	cin>>n>>m>>k;
	vector<char> chara(n+1);
	for(int i=1;i<=n;i++){
		cin>>chara[i];
	}
	vector<vector<int>> g(n+1);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector<set<int>> v(n+1);
	
	for(int j=1;j<=n;j++){
		queue<int> que;
		vector<int> dist(n+1,-1);
		que.push(j);
		char nowc=chara[j];
		dist[j]=0;
		while(!que.empty()){
			int pos=que.front();
			que.pop();
			for(int i=0;i<g[pos].size();i++){
				int to=g[pos][i];
				if(dist[to]==-1){
					dist[to]=dist[pos]+1;
					char nextc=chara[to];
					if(dist[to]<=k){
						if(nowc=='a'){
							if(nextc=='z' or nextc=='b'){
								v[j].insert(to);
								v[to].insert(j);
							}

						}else if(nowc=='z'){
							if(nextc=='a' or nextc=='y'){
								v[j].insert(to);
								v[to].insert(j);
							}
						}else if(abs(nextc-nowc)==1){
								v[j].insert(to);
								v[to].insert(j);
						}
						que.push(to);
					}
				}
			}
		}
	}
	set<int> exist;
	for(int i=1;i<=n;i++){
		if(v[i].size()>0){
			exist.insert(i);
		}
	}




	int ans=0;
	while(!exist.empty()){



		int ma=0;
		int ind=-1;
		for(int i=1;i<=n;i++){
			if(v[i].size()>ma){
				ind=i;
				ma=v[i].size();
			}
		}
		exist.erase(ind);
		for(int i=0;i<ma;i++){
			for(int j:v[ind]){
				v[j].erase(ind);
				if(v[j].empty()){
					exist.erase(j);	
				}
			}
		}
		v[ind].clear();
		ans++;
	}
	OUT(ans);
}
accuracy: 0.14545454545454545
time_ms: 20
memory_kb: 4240
final_rank: 19

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 998244353;
const int inf = (1<<30);

const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};

vector<vector<ll>> g(310,vector<ll>(310,310)); 
vector<int> c(310);
void make_ebi(int n){
    for(int k =0; k<n; k++){
        for(int i = 0; i <n; i++){
            for(int j = 0; j<n; j++) g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
        }
    }
    rep(i,n){
        rep(j,n){
            if((int)c[i] != ((int)c[j]+1)%26 && (int)c[i] != ((int)c[j]+25)%26){
                 g[i][j] = 310;
                // cout<<"***"<<endl;
            }
        }
    }




}

// [lower, upper]
int random(int lower, int upper) {
    return (rand() % (upper + 1)) + lower;
}

vector<int> make_random_permutation(int n) {
    vector<int> a(n);
    iota(a.begin(), a.end(), 0);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    shuffle(a.begin(), a.end(), engine);

    return a;
}


int put_trap(int n,int k,vector<vector<ll>> g){
   int ans = 0;
   bool c = true;
   vector<int> x = make_random_permutation(n);
   while(c){
       c = false;
       int mg = 0;
       int a = -1;
       
       rep(i,n){
           //cout<<"!!"<<endl;
           int eg = 0;
           rep(j,n){
               if(g[x[i]][j] <= k) eg++;
           }
           if(eg > mg){
              // cout<<"??"<<endl;
               c = true;
               a = x[i];
               mg = eg;
           }
       }
       if(c == false) return ans;

       rep(i,n){
            g[a][i] = 310;
            g[i][a] = 310;
       }
       ans++;
   }

   return ans;
}


int main(){
    int n,m,k;
    cin>>n>>m>>k;
    rep(i,n){
        char p;
        cin>>p;
        c[i] = int(p-'a');
    }

    rep(i,m){
        int u,v; cin>>u>>v;
        u--;v--;
        g[u][v] = 1;
        g[v][u] = 1;
    }
    make_ebi(n);
    int ans = 310;
    rep(i,100){
        ans = min(ans,put_trap(n,k,g));
    }

    cout<<ans<<endl;
}
accuracy: 0.18181818181818182
time_ms: 970
memory_kb: 4672
final_rank: 15

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 998244353;
const int inf = (1<<30);

const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};

vector<vector<ll>> g(310,vector<ll>(310,310)); 
vector<int> c(310);
void make_ebi(int n){
    for(int k =0; k<n; k++){
        for(int i = 0; i <n; i++){
            for(int j = 0; j<n; j++) g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
        }
    }
    rep(i,n){
        rep(j,n){
            if((int)c[i] != ((int)c[j]+1)%26 && (int)c[i] != ((int)c[j]+25)%26){
                 g[i][j] = 310;
                // cout<<"***"<<endl;
            }
        }
    }




}


int put_trap(int n,int k){
   int ans = 0;
   bool c = true;
   while(c){
       c = false;
       int mg = 0;
       int a = -1;

       rep(i,n){
           //cout<<"!!"<<endl;
           int eg = 0;
           rep(j,n){
               if(g[i][j] <= k) eg++;
           }
           if(eg > mg){
              // cout<<"??"<<endl;
               c = true;
               a = i;
               mg = eg;
           }
       }
       if(c == false) return ans;

       rep(i,n){
            g[a][i] = 310;
            g[i][a] = 310;
       }
       ans++;
   }

   return ans;
}







int main(){
    int n,m,k;
    cin>>n>>m>>k;
    rep(i,n){
        char p;
        cin>>p;
        c[i] = int(p-'a');
    }

    rep(i,m){
        int u,v; cin>>u>>v;
        u--;v--;
        g[u][v] = 1;
        g[v][u] = 1;
    }
    make_ebi(n);
    cout<<put_trap(n,k)<<endl;




}
accuracy: 0.14545454545454545
time_ms: 20
memory_kb: 4244
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> C(N);
    for (auto& c : C) {
        char op; cin >> op;
        c = (int)op;
    }
    for (auto& c : C) c %= 26;

    const int INF = (int)1e9;
    vector G(N, vector(N, INF));
    for (int i = 0 ; i < N ; i++) G[i][i] = 0;

    for (int _ = 0 ; _ < M ; _++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u][v] = G[v][u] = 1;
    }

    for (int k = 0 ; k < N ; k++) {
        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < N ; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    vector<vector<int>> Ebi(N);
    for (int i = 0 ; i < N ; i++) {
        for (int j = i + 1 ; j < N ; j++) {
            if (G[i][j] > K) continue;
            // cout << C[i] << ' ' << C[j] << ' ' << (C[i] - C[j] + 26) % 26 << endl;
            int score = (C[i] - C[j] + 26) % 26;
            if (score == 1 or score == 25) {
                Ebi[i].push_back(j);
                Ebi[j].push_back(i);
            }
        }
    }


    vector<int> id(N, -1);
    int size = 0;
    
    auto dfsid = [&](auto dfsid, int v) -> void {
        id[v] = size;
        for (auto x : Ebi[v]) if (id[x] == -1) {
            dfsid(dfsid, x);
        }
    };

    for (int i = 0 ; i < N ; i++) {
        if (id[i] == -1) {
            dfsid(dfsid, i);
            size++;
        }
    }

    vector<int> col(N, -1); 

    auto dfscol = [&](auto dfscol, int v, int c) -> void {
        col[v] = c;
        for (auto x : Ebi[v]) {
            if (col[x] != -1) {
                assert(col[x] == 1 - c);
            }
            else {
                dfscol(dfscol, x, 1 - c);
            }
        }
    };

    for (int i = 0 ; i < N ; i++) {
        if (col[i] == -1) {
            dfscol(dfscol, i, 0);
        }
    }

    vector<int> zero(size), one(size);
    for (int i = 0 ; i < N ; i++) {
        if (col[i] == 0) {
            zero[id[i]]++;
        }
        else {
            one[id[i]]++;
        }
    }
    
    int ans = 0;
    for (int i = 0 ; i < size ; i++) {
        ans += min(zero[i], one[i]);
    }

    cout << ans << endl;
}
accuracy: 0.14545454545454545
time_ms: 20
memory_kb: 3576
final_rank: 17

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3168.cc: Capture Ebichan
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<bool> vb;

/* global variables */

int cs[MAX_N], ds[MAX_N], gids[MAX_N];
vi nbrs[MAX_N], gnbrs[MAX_N], enbrs[MAX_N];
bool used[MAX_N];

/* subroutines */

void bfs(int n, int k, int st) {
  int c1 = (cs[st] + 25) % 26, c2 = (cs[st] + 1) % 26;
  fill(ds, ds + n, -1);
  ds[st] = 0;

  qi q;
  q.push(st);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (ds[u] >= k) continue;

    for (auto v: nbrs[u])
      if (ds[v] < 0) {
	ds[v] = ds[u] + 1;
	q.push(v);

	if (ds[v] <= k && (cs[v] == c1 || cs[v] == c2))
	  gnbrs[gids[st]].push_back(gids[v]);
      }
  }
}

bool max_match_rec(const vi *nbrs, int u, vi &matches, vb &visited) {
  if (u < 0) return true;
  for (const int v: nbrs[u]) {
    if (! visited[v]) {
      visited[v] = true;
      if (max_match_rec(nbrs, matches[v], matches, visited)) {
	matches[u] = v;
	matches[v] = u;
	return true;
      }
    }
  }
  return false;
}

int max_match(const int n, int l, const vi *nbrs, vi &matches) {
  matches.assign(n, -1);
  int count = 0;
  
  for (int u = 0; u < l; u++) {
    vb visited(n, false);
    if (max_match_rec(nbrs, u, matches, visited)) count++;
  }

  return count;
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) {
    char w[4];
    scanf("%s", w);
    cs[i] = w[0] - 'a';
  }

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  int l = 0;
  for (int u = 0; u < n; u++)
    if (! (cs[u] & 1)) l++;

  for (int u = 0, i = 0, j = 0; u < n; u++) {
    if (! (cs[u] & 1)) gids[u] = i++;
    else gids[u] = l + j++;
  }
  //for (int u = 0; u < n; u++) printf("%d ", gids[u]); putchar('\n');

  for (int u = 0; u < n; u++) bfs(n, k, u);

  vi matches;
  int mm = max_match(n, l, gnbrs, matches);
  //printf("mm=%d\n", mm);
  //for (int i = 0; i < l; i++) printf("%d->%d ", i, matches[i]);
  //putchar('\n');

  qi q;
  for (int u = 0; u < l; u++) {
    for (auto v: gnbrs[u]) {
      if (matches[u] == v) enbrs[v].push_back(u);
      else enbrs[u].push_back(v);
    }
    if (matches[u] < 0)
      used[u] = true, q.push(u);
  }

  while (! q.empty()) {
    int u = q.front(); q.pop();
    for (auto v: nbrs[u])
      if (! used[v])
	used[v] = true, q.push(v);
  }

  int cnt = 0;
  for (int u = 0; u < l; u++)
    if (! gnbrs[u].empty() && ! used[u]) cnt++;
  for (int u = l; u < n; u++)
    if (! gnbrs[u].empty() && used[u]) cnt++;

  printf("%d\n", cnt);
  return 0;
}
accuracy: 0.14545454545454545
time_ms: 10
memory_kb: 3468
final_rank: 16

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3168.cc: Capture Ebichan
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<bool> vb;

/* global variables */

int cs[MAX_N], ds[MAX_N], gids[MAX_N];
vi nbrs[MAX_N], gnbrs[MAX_N], enbrs[MAX_N];
bool used[MAX_N];

/* subroutines */

void bfs(int n, int k, int st) {
  int c1 = (cs[st] + 25) % 26, c2 = (cs[st] + 1) % 26;
  fill(ds, ds + n, -1);
  ds[st] = 0;

  qi q;
  q.push(st);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (ds[u] >= k) continue;

    for (auto v: nbrs[u])
      if (ds[v] < 0) {
	ds[v] = ds[u] + 1;
	q.push(v);

	if (ds[v] <= k && (cs[v] == c1 || cs[v] == c2)) {
	  gnbrs[gids[st]].push_back(gids[v]);
	  gnbrs[gids[v]].push_back(gids[st]);
	}
      }
  }
}

bool max_match_rec(const vi *nbrs, int u, vi &matches, vb &visited) {
  if (u < 0) return true;
  for (const int v: nbrs[u]) {
    if (! visited[v]) {
      visited[v] = true;
      if (max_match_rec(nbrs, matches[v], matches, visited)) {
	matches[u] = v;
	matches[v] = u;
	return true;
      }
    }
  }
  return false;
}

int max_match(const int n, int l, const vi *nbrs, vi &matches) {
  matches.assign(n, -1);
  int count = 0;
  
  for (int u = 0; u < l; u++) {
    vb visited(n, false);
    if (max_match_rec(nbrs, u, matches, visited)) count++;
  }

  return count;
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) {
    char w[4];
    scanf("%s", w);
    cs[i] = w[0] - 'a';
  }

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  int l = 0;
  for (int u = 0; u < n; u++)
    if (! (cs[u] & 1)) l++;

  for (int u = 0, i = 0, j = 0; u < n; u++) {
    if (! (cs[u] & 1)) gids[u] = i++;
    else gids[u] = l + j++;
  }
  //for (int u = 0; u < n; u++) printf("%d ", gids[u]); putchar('\n');

  for (int u = 0; u < n; u++) bfs(n, k, u);

  vi matches;
  int mm = max_match(n, l, gnbrs, matches);
  //printf("mm=%d\n", mm);
  //for (int i = 0; i < l; i++) printf("%d->%d ", i, matches[i]);
  //putchar('\n');

  qi q;
  for (int u = 0; u < l; u++) {
    for (auto v: gnbrs[u]) {
      if (matches[u] == v) enbrs[v].push_back(u);
      else enbrs[u].push_back(v);
    }
    if (matches[u] < 0)
      used[u] = true, q.push(u);
  }

  while (! q.empty()) {
    int u = q.front(); q.pop();
    for (auto v: nbrs[u])
      if (! used[v])
	used[v] = true, q.push(v);
  }

  int cnt = 0;
  for (int u = 0; u < l; u++)
    if (! gnbrs[u].empty() && ! used[u]) cnt++;
  for (int u = l; u < n; u++)
    if (! gnbrs[u].empty() && used[u]) cnt++;

  printf("%d\n", cnt);
  return 0;
}
accuracy: 0.14545454545454545
time_ms: 10
memory_kb: 3628
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

namespace atcoder {
 
namespace internal {
 
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
 
}  // namespace internal
 
}  // namespace atcoder
namespace atcoder {
 
template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    mf_graph(int n) : _n(n), g(n) {}
 
    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
 
    struct edge {
        int from, to;
        Cap cap, flow;
    };
 
    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
 
    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
 
        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;
 
        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) break;
            }
            return res;
        };
 
        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                Cap f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
 
    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
 
  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};
 
}  // namespace atcoder
using namespace atcoder;

void Warshall_Floyd(std::vector<std::vector<int>> &G){
	int N=G.size();
	assert(N==(int)G[0].size());
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(G[i][j]>G[i][k]+G[k][j]){
					G[i][j]=G[i][k]+G[k][j];
				}
			}
		}
	}
}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M,K;
	cin>>N>>M>>K;
	vector<char> p(N);
	rep(i,N) cin>>p[i];
	vector<vector<int>> G(N,vector<int>(N,INF));
	rep(i,N) G[i][i]=0;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a][b]=1;
		G[b][a]=1;
	}
	Warshall_Floyd(G);
	mf_graph<int> mfg(N+2);
	rep(i,N){
		if((p[i]-'a')%2){
			mfg.add_edge(i,N+1,1);
			continue;
		}
		mfg.add_edge(N,i,1);
		rep(j,N){
			if(G[i][j]<=K&&(abs(13-abs(p[i]-p[j]))==12)){
				mfg.add_edge(i,j,1);
			}
		}
	}
	int ans=mfg.flow(N,N+1);
	cout<<ans<<"\n";
}
accuracy: 1
time_ms: 20
memory_kb: 4596
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

namespace atcoder {
 
namespace internal {
 
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
 
}  // namespace internal
 
}  // namespace atcoder
namespace atcoder {
 
template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    mf_graph(int n) : _n(n), g(n) {}
 
    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
 
    struct edge {
        int from, to;
        Cap cap, flow;
    };
 
    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
 
    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
 
        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;
 
        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) break;
            }
            return res;
        };
 
        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                Cap f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
 
    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
 
  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};
 
}  // namespace atcoder
using namespace atcoder;

void Warshall_Floyd(std::vector<std::vector<int>> &G){
	int N=G.size();
	assert(N==(int)G[0].size());
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(G[i][j]>G[i][k]+G[k][j]){
					G[i][j]=G[i][k]+G[k][j];
				}
			}
		}
	}
}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M,K;
	cin>>N>>M>>K;
	vector<char> p(N);
	rep(i,N) cin>>p[i];
	vector<vector<int>> G(N,vector<int>(N,INF));
	rep(i,N) G[i][i]=0;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a][b]=1;
		G[b][a]=1;
	}
	Warshall_Floyd(G);
	mf_graph<int> mfg(N+2);
	rep(i,N){
		if((p[i]-'a')%2){
			mfg.add_edge(i,N+1,1);
			continue;
		}
		mfg.add_edge(N,i,1);
		rep(j,N){
			if(G[i][j]<=K&&(abs(13-abs(p[i]-p[j]))==12)){
				mfg.add_edge(i,j,1);
			}
		}
	}
	int ans=mfg.flow(N,N+1);
	cout<<ans<<"\n";
}
accuracy: 0.6909090909090909
time_ms: 20
memory_kb: 4624
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

namespace atcoder {
 
namespace internal {
 
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
 
}  // namespace internal
 
}  // namespace atcoder
namespace atcoder {
 
template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    mf_graph(int n) : _n(n), g(n) {}
 
    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
 
    struct edge {
        int from, to;
        Cap cap, flow;
    };
 
    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
 
    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
 
        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;
 
        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) break;
            }
            return res;
        };
 
        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                Cap f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
 
    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
 
  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};
 
}  // namespace atcoder
using namespace atcoder;

void Warshall_Floyd(std::vector<std::vector<int>> &G){
	int N=G.size();
	assert(N==(int)G[0].size());
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(G[i][j]>G[i][k]+G[k][j]){
					G[i][j]=G[i][k]+G[k][j];
				}
			}
		}
	}
}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M,K;
	cin>>N>>M>>K;
	vector<char> p(N);
	rep(i,N) cin>>p[i];
	vector<vector<int>> G(N,vector<int>(N,INF));
	rep(i,N) G[i][i]=0;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a][b]=1;
		G[b][a]=0;
	}
	Warshall_Floyd(G);
	mf_graph<int> mfg(N+2);
	rep(i,N){
		if((p[i]-'a')%2){
			mfg.add_edge(i,N+1,1);
			continue;
		}
		mfg.add_edge(N,i,1);
		rep(j,N){
			if(G[i][j]<=K&&(abs(13-abs(p[i]-p[j]))==12)){
				mfg.add_edge(i,j,1);
			}
		}
	}
	int ans=mfg.flow(N,N+1);
	cout<<ans<<"\n";
}
accuracy: 0.6909090909090909
time_ms: 20
memory_kb: 4600
final_rank: 12

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 4 "/home/yuruhiya/programming/library/template/constants.cpp"
#include <string_view>
#line 7 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
namespace CharacterClass {
	constexpr string_view
	    digit = "0123456789",
	    xdigit = "0123456789ABCDEFabcdef", lower = "abcdefghijklmnopqrstuvwxyz",
	    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    word = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
	    punct = R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)",
	    graph =
	        R"(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    print =
	        R"( !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    blank = " \t", space = " \t\n\r\f\v";
}  // namespace CharacterClass
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Printer {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? B.t : B.f);
	}
	void print(vector<bool>::reference v) const {
		print(v ? B.t : B.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void print(double v) const {
		printf("%.20f", v);
	}
	void print(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void print(const T& v) const {
		cout << v;
	}
	template <class T, class U> void print(const pair<T, U>& v) const {
		print(v.first);
		print(D.d);
		print(v.second);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(D.d);
			print(*i);
		}
	}
	template <class T> void print(const vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, size_t N> void print(const array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) print(D.l);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Printer& operator()() {
		print(D.l);
		return *this;
	}
	template <class H> Printer& operator()(H&& h) {
		print(h);
		print(D.l);
		return *this;
	}
	template <class H, class... T> Printer& operator()(H&& h, T&&... t) {
		print(h);
		print(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(D.l);
		return *this;
	}
	template <class T> Printer& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Printer& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Printer& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T> constexpr int BIT(T x, int i) {
	return (x & (1 << i)) ? 1 : 0;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 4 "/home/yuruhiya/programming/library/Graph/ShortestPath.cpp"
#include <optional>
#line 6 "/home/yuruhiya/programming/library/Graph/ShortestPath.cpp"
using namespace std;

vector<int> ShortestPath(const vector<vector<int>>& graph, int s,
                         int inf = numeric_limits<int>::max()) {
	int V = graph.size();
	vector<int> dist(V, inf);
	dist[s] = 0;
	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int f = que.front();
		que.pop();
		for (auto e : graph[f]) {
			if (dist[e] == inf) {
				que.push(e);
				dist[e] = dist[f] + 1;
			}
		}
	}
	return dist;
}
int ShortestPathST(const vector<vector<int>>& graph, int s, int t,
                 int inf = numeric_limits<int>::max()) {
	size_t n = graph.size();
	vector<int> dist(n, inf);
	dist[s] = 0;
	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		if (v == t) return dist[t];
		que.pop();
		for (auto u : graph[v]) {
			if (dist[u] == inf) {
				que.push(u);
				dist[u] = dist[v] + 1;
			}
		}
	}
	return dist[t];
}
#line 6 "/home/yuruhiya/programming/library/Graph/BipartiteMatching.cpp"
using namespace std;

class BipartiteMatching {
	size_t left, right;
	vector<vector<int>> graph;
	vector<bool> used;
	vector<int> left_match, right_match;
	bool dfs(int v) {
		if (used[v]) {
			return false;
		}
		used[v] = true;
		for (int u : graph[v]) {
			if (right_match[u] == -1 || dfs(right_match[u])) {
				left_match[v] = u;
				right_match[u] = v;
				return true;
			}
		}
		return false;
	}

public:
	BipartiteMatching(size_t _left, size_t _right)
	    : left(_left),
	      right(_right),
	      graph(left),
	      used(left),
	      left_match(left),
	      right_match(right) {}
	BipartiteMatching(size_t _left, size_t _right, const vector<vector<int>>& _graph)
	    : left(_left),
	      right(_right),
	      graph(_graph),
	      used(left),
	      left_match(left),
	      right_match(right) {
		assert(graph.size() == left);
	}
	void add_edge(int l, int r) {
		graph[l].push_back(r);
	}
	int solve() {
		int result = 0;
		fill(left_match.begin(), left_match.end(), -1);
		fill(right_match.begin(), right_match.end(), -1);
		fill(used.begin(), used.end(), false);
		for (bool update = true; update;) {
			update = false;
			for (size_t i = 0; i < left; ++i) {
				if (left_match[i] == -1 && dfs(i)) {
					update = true;
					++result;
				}
			}
			if (update) {
				fill(used.begin(), used.end(), false);
			}
		}
		return result;
	}
	vector<pair<int, int>> edges() const {
		vector<pair<int, int>> result;
		for (size_t i = 0; i < left; ++i) {
			if (left_match[i] != -1) {
				result.emplace_back(i, left_match[i]);
			}
		}
		return result;
	}
};
#line 4 "a.cpp"

int main() {
	ini(n, m, k);
	VI c = step(n) | Map([&](int i) { return in.read<char>() - 'a'; });
	dump(c);
	VVI g(n);
	rep(i, m) {
		int u = in--, v = in--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	VVI d = step(n) | Map([&](int i) { return ShortestPath(g, i, inf); });

	BipartiteMatching bg(n, n);
	rep(i, n) FOR(j, i + 1, n) {
		if (d[i][j] <= k && ((c[i] + 1) % 26 == c[j] || (c[j] + 1) % 26 == c[i])) {
			int a = i, b = j;
			if (c[a] % 2 == 1) swap(a, b);
			bg.add_edge(a, b);
		}
	}
	out(bg.solve());
}
accuracy: 1
time_ms: 20
memory_kb: 4492
final_rank: 1