답안 #703998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703998 2023-03-01T09:23:50 Z Pacybwoah Kutije (COCI21_kutije) C++14
70 / 70
147 ms 9516 KB
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
vector<int> dsu,sz;
int query(int x){
    if(x==dsu[x]) return x;
    int tmp=query(dsu[x]);
    dsu[x]=tmp;
    return tmp;
}
void unite(int a,int b){
    a=query(a);
    b=query(b);
    if(a==b) return;
    if(sz[a]>sz[b]){
        dsu[b]=a;
        sz[a]+=sz[b];
    }
    else{
        dsu[a]=b;
        sz[b]+=sz[a];
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    dsu.resize(n+1);
    sz.resize(n+1);
    for(int i=1;i<=n;i++){
        dsu[i]=i;
        sz[i]=1;
    }
    int tmpp;
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            cin>>tmpp;
            unite(tmpp,j);
        }
    }
    int a,b;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        if(query(a)==query(b)) cout<<"DA\n";
        else cout<<"NE\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 5600 KB Output is correct
2 Correct 66 ms 4912 KB Output is correct
3 Correct 65 ms 4668 KB Output is correct
4 Correct 74 ms 5540 KB Output is correct
5 Correct 76 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 328 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 328 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 5600 KB Output is correct
2 Correct 66 ms 4912 KB Output is correct
3 Correct 65 ms 4668 KB Output is correct
4 Correct 74 ms 5540 KB Output is correct
5 Correct 76 ms 5624 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 141 ms 9416 KB Output is correct
27 Correct 144 ms 9396 KB Output is correct
28 Correct 125 ms 7720 KB Output is correct
29 Correct 143 ms 9008 KB Output is correct
30 Correct 129 ms 8072 KB Output is correct
31 Correct 147 ms 7980 KB Output is correct
32 Correct 146 ms 9388 KB Output is correct
33 Correct 143 ms 9328 KB Output is correct
34 Correct 131 ms 9420 KB Output is correct
35 Correct 146 ms 9516 KB Output is correct