제출 #987921

#제출 시각아이디문제언어결과실행 시간메모리
987921AugustynKutije (COCI21_kutije)C++17
35 / 70
1054 ms13672 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ssize(a) ((int)(a.size()))

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>>pol(n);
    for(int i = 0; i < m; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            int pi;
            cin >> pi;
            --pi;
            pol[j].push_back(pi);
        }
    }

    vector<vector<bool>>jest_pol(n, vector<bool>(n));
    for(int i = 0; i < n; ++i)
    {
        queue<int>kol;
        kol.push(i);
        jest_pol[i][i] = 1;
        while(!kol.empty())
        {
            int t = kol.front();
            kol.pop();
            for(auto j: pol[t])
                if(jest_pol[i][j] == 0)
                {
                    jest_pol[i][j] = 1;
                    kol.push(j);
                }
        }
    }
    while(q)
    {
        --q;
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if(jest_pol[a][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...