Submission #522235

# Submission time Handle Problem Language Result Execution time Memory
522235 2022-02-04T08:47:42 Z blue Kutije (COCI21_kutije) C++17
70 / 70
175 ms 18284 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <string>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const int mx = 1'000;

vvi edge(1+mx);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, q;
    cin >> n >> m >> q;

    for(int j = 1; j <= m; j++)
    {
        for(int i = 1; i <= n; i++)
        {
            int p;
            cin >> p;

            edge[p].push_back(i);
            edge[i].push_back(p);
        }
    }

    vi cc(1+n, 0);
    int cc_count = 0;

    for(int i = 1; i <= n; i++)
    {
        if(cc[i]) continue;
        cc_count++;

        cc[i] = cc_count;

        queue<int> tbv;
        tbv.push(i);
        while(!tbv.empty())
        {
            int u = tbv.front();
            tbv.pop();

            for(int v: edge[u])
            {
                if(cc[v]) continue;
                cc[v] = cc_count;
                tbv.push(v);
            }
        }
    }

    for(int x = 1; x <= q; x++)
    {
        int a, b;
        cin >> a >> b;

        if(cc[a] == cc[b]) cout << "DA\n";
        else cout << "NE\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 85 ms 5656 KB Output is correct
2 Correct 62 ms 4964 KB Output is correct
3 Correct 89 ms 4696 KB Output is correct
4 Correct 69 ms 5628 KB Output is correct
5 Correct 70 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 476 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 476 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 1 ms 388 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 5656 KB Output is correct
2 Correct 62 ms 4964 KB Output is correct
3 Correct 89 ms 4696 KB Output is correct
4 Correct 69 ms 5628 KB Output is correct
5 Correct 70 ms 5592 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 452 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 2 ms 464 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 158 ms 18184 KB Output is correct
27 Correct 175 ms 18284 KB Output is correct
28 Correct 125 ms 15908 KB Output is correct
29 Correct 156 ms 17808 KB Output is correct
30 Correct 134 ms 15556 KB Output is correct
31 Correct 133 ms 16068 KB Output is correct
32 Correct 143 ms 17596 KB Output is correct
33 Correct 157 ms 17468 KB Output is correct
34 Correct 144 ms 17484 KB Output is correct
35 Correct 152 ms 17940 KB Output is correct