Submission #874848

# Submission time Handle Problem Language Result Execution time Memory
874848 2023-11-18T00:16:05 Z tsumondai Kutije (COCI21_kutije) C++14
70 / 70
123 ms 9556 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e3 + 5;
 
const int oo = 1e18, mod = 1e9 + 7;
 
int n, m, k, q, lab[N];
int p[1005][1005];
vector<int> adj[N];

// da: yes
// ne: no

void make_set(int v) {
    lab[v] = -1;
}

int find_set(int v) {
    return lab[v] < 0 ? v : lab[v] = find_set(lab[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    
    if (a != b) {
        if (lab[a] > lab[b]) swap(a, b);
        lab[a] += lab[b];
        lab[b] = a;
    }
}


void process() {
	cin >> n >> m >> q; // so mon qua, so ban cua nvc, so query hoi
	foru(i,1,n) make_set(i);
	foru(i,1,m) {
		foru(j,1,n) {
			int x; cin >> x;
			union_sets(j, x);
		}
	}

	foru(i,1,q) {
		int a, b; cin >> a >> b;
		if (find_set(a)==find_set(b)) {
			cout << "DA\n";
		} else {
			cout << "NE\n";
		}
	}


    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Calm down and get VOI 
Flow:
tu a den b co duong di hay khong?
tao do thi -> dfs
*/
# Verdict Execution time Memory Grader output
1 Correct 64 ms 5716 KB Output is correct
2 Correct 55 ms 4992 KB Output is correct
3 Correct 53 ms 4692 KB Output is correct
4 Correct 62 ms 5716 KB Output is correct
5 Correct 67 ms 5724 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 524 KB Output is correct
5 Correct 1 ms 348 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 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 524 KB Output is correct
5 Correct 1 ms 348 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 348 KB Output is correct
11 Correct 1 ms 504 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 428 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 5716 KB Output is correct
2 Correct 55 ms 4992 KB Output is correct
3 Correct 53 ms 4692 KB Output is correct
4 Correct 62 ms 5716 KB Output is correct
5 Correct 67 ms 5724 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 524 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 348 KB Output is correct
16 Correct 1 ms 504 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 428 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 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 116 ms 9464 KB Output is correct
27 Correct 119 ms 9552 KB Output is correct
28 Correct 94 ms 7892 KB Output is correct
29 Correct 114 ms 9180 KB Output is correct
30 Correct 105 ms 8016 KB Output is correct
31 Correct 105 ms 8148 KB Output is correct
32 Correct 114 ms 9552 KB Output is correct
33 Correct 119 ms 9432 KB Output is correct
34 Correct 123 ms 9556 KB Output is correct
35 Correct 120 ms 9556 KB Output is correct