Submission #639178

# Submission time Handle Problem Language Result Execution time Memory
639178 2022-09-08T21:11:11 Z delrey Kutije (COCI21_kutije) C++14
70 / 70
960 ms 13376 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, q;
int p[1000][1000];
int u[1000], s[1000];
bool vis[1000];

int Root(int x)
{
    while(x != u[x])
        x = u[x];
    return x;
}

void Unite(int x, int y)
{
    x = Root(x);
    y = Root(y);
    if(x == y)
        return;
    if(s[x] > s[y])
        swap(x, y);
    u[x] = y;
    s[y] += s[x];
}

int main()
{
    cin>>n>>m>>q;
    for(int i = 0; i < m; i++)
        for(int j = 0; j < n; j++)
        {
            cin>>p[i][j];
            p[i][j]--;
        }
    for(int i = 0; i < n; i++)
    {
        u[i] = i;
        s[i] = 1;
    }
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < n; j++)
            vis[j] = false;
        for(int j = 0; j < n; j++)
        {
            if(vis[j])
                continue;
            vis[j] = true;
            int x = p[i][j];
            while(x != j)
            {
                vis[x] = true;
                Unite(x, j);
                x = p[i][x];
            }
        }
    }
    //for(int i = 0; i < n; i++)
    //    cout<<u[i]<<" ";
    //cout<<endl;
    for(int i = 0; i < q; i++)
    {
        int x, y;
        cin>>x>>y;
        x--;
        y--;
        if(Root(x) == Root(y))
            cout<<"DA"<<endl;
        else
            cout<<"NE"<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 752 ms 5584 KB Output is correct
2 Correct 662 ms 4856 KB Output is correct
3 Correct 622 ms 4552 KB Output is correct
4 Correct 757 ms 5620 KB Output is correct
5 Correct 759 ms 5600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 704 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 704 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 3 ms 652 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 704 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 752 ms 5584 KB Output is correct
2 Correct 662 ms 4856 KB Output is correct
3 Correct 622 ms 4552 KB Output is correct
4 Correct 757 ms 5620 KB Output is correct
5 Correct 759 ms 5600 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 3 ms 704 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 3 ms 652 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 2 ms 704 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 704 KB Output is correct
26 Correct 960 ms 13312 KB Output is correct
27 Correct 953 ms 13300 KB Output is correct
28 Correct 789 ms 11260 KB Output is correct
29 Correct 912 ms 12868 KB Output is correct
30 Correct 787 ms 11916 KB Output is correct
31 Correct 789 ms 11816 KB Output is correct
32 Correct 944 ms 13248 KB Output is correct
33 Correct 937 ms 13192 KB Output is correct
34 Correct 944 ms 13376 KB Output is correct
35 Correct 949 ms 13272 KB Output is correct