180022025-09-25 09:44:40ubormaciTom és Jerry 1 (80)cpp17Időlimit túllépés 64/80600ms6632 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int64_t ll;

void solve() {

    ll n, m, tom, jp, je;
    cin >> n >> m >> tom >> jp >> je;

    vector<vector<pair<ll,ll>>> v(n+1);
    for(ll i = 0; i < m; i++) {
        ll a, b, cost;
        cin >> a >> b >> cost;
        v[a].push_back({b, cost});
        v[b].push_back({a, cost});
    }

    // we do a tom-bfs

    // the bfs is a rooted tree starting from the bfs-start position
    // for jerry, if we have any road wherein our distance is less than tom's, it's good

    const ll inf = INT64_MAX / 2;

    vector<ll> tomd(n+1, inf);
    queue<ll> q;
    q.push(tom);
    tomd[tom] = 0;
    while(!q.empty()) {
        ll curr = q.front();
        q.pop();

        for(const auto & [neigh, cost] : v[curr]) {
            if(cost == 2 && tomd[neigh] == inf) {
                tomd[neigh] = tomd[curr] + 1;
                q.push(neigh);
            }
        }
    }

    for(ll qi = 0; qi < jp; qi++) {

        ll jstart;
        cin >> jstart;

        vector<ll> jd(n+1, inf);
        jd[jstart] = 0;

        q.push(jstart);
        while(!q.empty()) {
            ll curr = q.front();
            q.pop();

            if(jd[curr] >= tomd[curr]) {
                continue;
            }

            for(const auto & [neigh, cost] : v[curr]) {
                
                if(jd[neigh] == inf) {

                    jd[neigh] = jd[curr] + 1;
                    q.push(neigh);
                }
            }
        }

        if(jd[je] < inf) {
            cout << "IGEN\n";
        }else{
            cout << "NEM\n";
        }

    }

}

int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    solve();

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base64/80
1Elfogadva0/01ms316 KiB
2Elfogadva0/02ms564 KiB
3Elfogadva4/41ms316 KiB
4Elfogadva4/41ms316 KiB
5Elfogadva4/41ms316 KiB
6Elfogadva4/41ms316 KiB
7Elfogadva4/41ms316 KiB
8Elfogadva4/42ms316 KiB
9Elfogadva4/42ms516 KiB
10Elfogadva4/42ms564 KiB
11Elfogadva4/46ms996 KiB
12Elfogadva4/48ms1412 KiB
13Elfogadva4/414ms1844 KiB
14Elfogadva4/427ms3344 KiB
15Elfogadva4/441ms4312 KiB
16Elfogadva4/443ms5240 KiB
17Elfogadva4/467ms6216 KiB
18Elfogadva4/443ms4492 KiB
19Időlimit túllépés0/4600ms4552 KiB
20Időlimit túllépés0/4600ms4580 KiB
21Időlimit túllépés0/4583ms3976 KiB
22Időlimit túllépés0/4586ms6632 KiB