Submission #496637

# Submission time Handle Problem Language Result Execution time Memory
496637 2021-12-21T17:21:52 Z JovanB Kutije (COCI21_kutije) C++17
70 / 70
175 ms 13544 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 1000;

vector <int> graf[N+5];
bool visited[N+5];
int comp[N+5];

void dfs(int v, int p){
    comp[v] = p;
    visited[v] = 1;
    for(auto c : graf[v]) if(!visited[c]) dfs(c, p);
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m, qrs;
    cin >> n >> m >> qrs;
    int cnt = 0;
    for(int j=1; j<=m; j++){
        for(int i=1; i<=n; i++){
            int x;
            cin >> x;
            graf[i].push_back(x);
            graf[x].push_back(i);
        }
    }
    for(int i=1; i<=n; i++){
        if(!comp[i]){
            cnt++;
            dfs(i, cnt);
        }
    }
    while(qrs--){
        int a, b;
        cin >> a >> b;
        cout << (comp[a] == comp[b] ? "DA\n" : "NE\n");
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 79 ms 5640 KB Output is correct
2 Correct 62 ms 4956 KB Output is correct
3 Correct 60 ms 4708 KB Output is correct
4 Correct 75 ms 5664 KB Output is correct
5 Correct 83 ms 5580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 404 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 1 ms 396 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 404 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 1 ms 396 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 2 ms 484 KB Output is correct
11 Correct 1 ms 404 KB Output is correct
12 Correct 2 ms 440 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 1 ms 400 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 396 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 5640 KB Output is correct
2 Correct 62 ms 4956 KB Output is correct
3 Correct 60 ms 4708 KB Output is correct
4 Correct 75 ms 5664 KB Output is correct
5 Correct 83 ms 5580 KB Output is correct
6 Correct 1 ms 404 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 396 KB Output is correct
9 Correct 1 ms 396 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 444 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 400 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 484 KB Output is correct
16 Correct 1 ms 404 KB Output is correct
17 Correct 2 ms 440 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 400 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 396 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 175 ms 13544 KB Output is correct
27 Correct 149 ms 13528 KB Output is correct
28 Correct 148 ms 12796 KB Output is correct
29 Correct 147 ms 13384 KB Output is correct
30 Correct 143 ms 12108 KB Output is correct
31 Correct 132 ms 12608 KB Output is correct
32 Correct 162 ms 13004 KB Output is correct
33 Correct 154 ms 12832 KB Output is correct
34 Correct 146 ms 12796 KB Output is correct
35 Correct 154 ms 13252 KB Output is correct