Submission #674508

#TimeUsernameProblemLanguageResultExecution timeMemory
674508Farhan_HYKutije (COCI21_kutije)C++14
70 / 70
150 ms25544 KiB
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
/// Benzema is the best player in the world
const int N = 1003;
int n, m, q, a[N][N], comp[N];
vector<int> adj[N];

void dfs(int node, int col) {
    comp[node] = col;
    for(auto x: adj[node])
        if (!comp[x])
            dfs(x, col);
}

main() {
    IOS
    cin >> n >> m >> q;
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++)
            cin >> a[i][j], adj[j].push_back(a[i][j]);
    }
    int col = 0;
    for(int i = 1; i <= n; i++) {
        if (comp[i] == 0)
            dfs(i, ++col);
    }
    while(q--) {
        int u, v;
        cin >> u >> v;
        if (comp[u] == comp[v]) cout << "DA\n";
        else cout << "NE\n";
    }
}

Compilation message (stderr)

Main.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...