Submission #744863

# Submission time Handle Problem Language Result Execution time Memory
744863 2023-05-19T07:09:01 Z sword060 Kutije (COCI21_kutije) C++17
70 / 70
158 ms 9400 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int x,k,q,p[N],s[N],a[N];
int get(int a){
  return (a==p[a]?a:p[a]=get(p[a]));
}
void merge(int l,int r){
  l=get(l),r=get(r);
  if(l==r)return;
  if(s[l]>s[r])swap(l,r);
  s[r]+=s[l];
  p[l]=r;
}
int main(){
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>x>>k>>q;
  for(int i=1;i<=x;i++)p[i]=i,s[i]=1;
  for(int j=1;j<=k;j++){
    for(int i=1;i<=x;i++)cin>>a[i];
    for(int i=1;i<=x;i++)merge(i,a[i]);
  }
  while(q--){
    int l,r;cin>>l>>r;
    cout<<(get(l)==get(r)?"DA":"NE")<<"\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 81 ms 5580 KB Output is correct
2 Correct 78 ms 4812 KB Output is correct
3 Correct 83 ms 4656 KB Output is correct
4 Correct 85 ms 5608 KB Output is correct
5 Correct 97 ms 5588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 364 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 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 5580 KB Output is correct
2 Correct 78 ms 4812 KB Output is correct
3 Correct 83 ms 4656 KB Output is correct
4 Correct 85 ms 5608 KB Output is correct
5 Correct 97 ms 5588 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 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 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 364 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 336 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 143 ms 9400 KB Output is correct
27 Correct 141 ms 9360 KB Output is correct
28 Correct 120 ms 7720 KB Output is correct
29 Correct 144 ms 9096 KB Output is correct
30 Correct 135 ms 7976 KB Output is correct
31 Correct 130 ms 8012 KB Output is correct
32 Correct 136 ms 9344 KB Output is correct
33 Correct 158 ms 9356 KB Output is correct
34 Correct 144 ms 9380 KB Output is correct
35 Correct 149 ms 9388 KB Output is correct