Submission #974062

# Submission time Handle Problem Language Result Execution time Memory
974062 2024-05-02T17:17:50 Z VinhLuu Kutije (COCI21_kutije) C++17
70 / 70
140 ms 9812 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()

using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e5 + 5;
const int oo = 1e9 + 1;
const int mod = 1e9 + 7;
//const ll oo = 5e18;

int n, pa[N], sz[N], m, q;

int fin(int u){
    return pa[u] == u ? u : pa[u] = fin(pa[u]);
}

void dsu(int x,int y){
    x = fin(x), y = fin(y);
    if(sz[x] < sz[y]) swap(x, y);
    pa[y] = x, sz[x] += sz[y];
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n >> m >> q;

    for(int i = 1; i <= n; i ++) pa[i] = i, sz[i] = 1;

    while(m--){
        for(int i = 1; i <= n; i++){
            int x; cin >> x;
            dsu(i, x);
        }
    }

    while(q--){
        int x, y; cin >> x >> y;
        cout << (fin(x) == fin(y) ? "DA" : "NE") << "\n";
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 75 ms 5712 KB Output is correct
2 Correct 63 ms 4916 KB Output is correct
3 Correct 62 ms 4944 KB Output is correct
4 Correct 73 ms 5712 KB Output is correct
5 Correct 82 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 476 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 476 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 5712 KB Output is correct
2 Correct 63 ms 4916 KB Output is correct
3 Correct 62 ms 4944 KB Output is correct
4 Correct 73 ms 5712 KB Output is correct
5 Correct 82 ms 5716 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 476 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 138 ms 9412 KB Output is correct
27 Correct 137 ms 9432 KB Output is correct
28 Correct 101 ms 7804 KB Output is correct
29 Correct 123 ms 9028 KB Output is correct
30 Correct 122 ms 8020 KB Output is correct
31 Correct 117 ms 8000 KB Output is correct
32 Correct 130 ms 9672 KB Output is correct
33 Correct 140 ms 9364 KB Output is correct
34 Correct 135 ms 9536 KB Output is correct
35 Correct 133 ms 9812 KB Output is correct