Submission #939318

#TimeUsernameProblemLanguageResultExecution timeMemory
939318blackavarKutije (COCI21_kutije)C++14
70 / 70
164 ms66076 KiB
#include <bits/stdc++.h>
using namespace std;

vector <long long> graph[1000005];
long long tplt[1000005], id = 1;

void dfs(long long u)
{
    for (auto v:graph[u])
    {
        if (tplt[v] != -1) continue;
        tplt[v] = id;
        dfs(v);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, m, q;
    cin >> n >> m >> q;
    long long p[m + 1][n + 1];
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> p[i][j];
            graph[j].push_back(p[i][j]);
            graph[p[i][j]].push_back(j);
        }
    }
    memset(tplt, -1, sizeof tplt);
    for (int i = 1; i <= n; i++)
    {
        if (tplt[i] == -1)
        {
            id++;
            dfs(i);
        }
    }
    for (int i = 1; i <= q; i++)
    {
        long long a, b;
        cin >> a >> b;
        if (tplt[a] == tplt[b]) cout << "DA" << "\n";
        else cout << "NE" << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...