24802023-01-13 12:06:21rennTom és Jerry2 (60)cpp11Wrong answer 0/60532ms10940 KiB
#include <bits/stdc++.h>
using namespace std;

#define InTheNameOfGod cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
typedef vector<vector<int>> graf;
typedef vector<int> vi;
typedef vector<bool> vb;

inline int bfs(graf &g, int &k, vi &tavok)
{
    queue<int> next;
    next.push(k);
    tavok[k] = 0;

    int i;
    while(!next.empty())
    {
        i = next.front();
        next.pop();

        for(auto &x : g[i])
        {
            if(tavok[x] > -1) continue;

            next.push(x);
            tavok[x] = tavok[i]+1;
        }
    }

    return 0;
}

int timer;
void jerry_dfs(int v, int p, graf &adj, vb &volt, queue<int> &cuts, vi &tin, vi &low, vi &dist) {
    volt[v] = true;
    tin[v] = low[v] = timer++;
    int children=0;
    for (int to : adj[v]) {
        if (to == p) continue;
        if (volt[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            jerry_dfs(to, v, adj, volt, cuts, tin, low, dist);
            low[v] = min(low[v], low[to]);
            if (low[to] >= tin[v] && p!=-1 && adj[v].size() > 1)
                cuts.push(v);
            ++children;
        }
    }
    if(p == -1 && children > 1 && adj[v].size() > 1)
        cuts.push(v);
}

int main()
{

    InTheNameOfGod

    int n, m, t, jdb, j, e;
    cin >> n >> m >> t >> jdb >> e;
    e--;
    t--;

    vi tomd(n, -1);
    graf tom(n);
    graf jerry(n);

    int a, b, c, d;
    bool h;

    while(m--)
    {
        cin >> a >> b >> c;
        a--; b--;

        if(((c&1)^1) && a!=e && b!=e)
        {
            tom[a].push_back(b);
            tom[b].push_back(a);
        }

        jerry[a].push_back(b);
        jerry[b].push_back(a);
    }

    bfs(tom, t, tomd);

    while(jdb--)
    {
        timer = 0;
        vi jerryd(n, -1);
        vb volt(n, false);
        vi tin(n, -1);
        vi low(n, -1);

        cin >> j;
        j--;

        queue<int> cuts;
        bfs(jerry, j, jerryd);
        jerry_dfs(j, -1, jerry, volt, cuts, tin, low, jerryd);

        h = false;
        for(auto &x : jerryd)
            cout << x << " ";
        cout << "\n";
        while(!cuts.empty())
        {
            d = cuts.front(); cuts.pop();
            if(jerryd[d] > tomd[d])
            {
                cout << d+1 << "\n";
                h = true;
                break;
            }
        }
        if(!h) cout << "0\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/60
1Wrong answer0/03ms1852 KiB
2Time limit exceeded0/0456ms2784 KiB
3Wrong answer0/22ms1972 KiB
4Wrong answer0/22ms2088 KiB
5Wrong answer0/22ms2288 KiB
6Wrong answer0/33ms2376 KiB
7Wrong answer0/24ms2648 KiB
8Wrong answer0/248ms2716 KiB
9Wrong answer0/221ms2780 KiB
10Wrong answer0/372ms2912 KiB
11Wrong answer0/385ms3276 KiB
12Wrong answer0/3333ms3792 KiB
13Time limit exceeded0/3460ms3140 KiB
14Time limit exceeded0/3474ms3600 KiB
15Time limit exceeded0/3465ms3980 KiB
16Time limit exceeded0/3469ms4220 KiB
17Time limit exceeded0/3532ms5616 KiB
18Time limit exceeded0/3460ms8116 KiB
19Time limit exceeded0/4472ms7340 KiB
20Time limit exceeded0/4469ms9648 KiB
21Time limit exceeded0/5446ms9480 KiB
22Time limit exceeded0/5521ms10940 KiB