Submission #961721

# Submission time Handle Problem Language Result Execution time Memory
961721 2024-04-12T11:09:24 Z danikoynov Making Friends on Joitter is Fun (JOI20_joitter2) C++14
1 / 100
5000 ms 2936 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

const int maxn = 2010;

int n, par[maxn], m;

int find_leader(int v)
{
    if (par[v] == v)
        return v;
    return (par[v] = find_leader(par[v]));
}

int ed[maxn][maxn];
void solve()
{
    cin >> n >> m;

    for (int i = 1; i <= m; i ++)
    {
        int v, u;
        cin >> v >> u;
        ed[v][u] = 1;
        bool change = true;
        while(change)
        {
            change = false;
            for (int y = 1; y <= n; y ++)

                for (int z = y + 1; z <= n; z ++)
                {

                    if (!(ed[y][z] && ed[z][y]))
                        continue;
                    for (int w = 1; w <= n; w ++)
                    {
                        if (w == y || w == z)
                            continue;
                            if (ed[w][z] + ed[w][y] == 1)
                              change = true;
                        if (ed[w][z] || ed[w][y])
                        {

                            ed[w][z] = ed[w][y] = 1;
                            ///change = true;
                        }

                    }
                }
        }

        ll edges = 0;
        for (int x = 1; x <= n; x ++)
            for (int y = 1; y <= n; y ++)
            {
                //if (v == u && ed[v][u])
                //   cout << "v " << v << endl;
                edges += ed[x][y];
            }
        cout << edges << endl;
        //for (int j = 1; j <= n; j ++)
        //cout << "sz " << j << " " << sz[j] << endl;

    }
}

int main()
{
    solve();
    return 0;
}
/**
6 7
1 2
2 3
3 4
4 5
5 6
6 5
5 4

5 9
3 1
5 1
3 4
5 2
1 2
5 4
3 5
2 4
1 3

2 5
4 5
4 3
4 2
2 3
3 2
5 3
2 1
1 5
4 1
1 4


*/

Compilation message

joitter2.cpp: In function 'void solve()':
joitter2.cpp:41:25: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   41 |                         if (w == y || w == z)
      |                         ^~
joitter2.cpp:43:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   43 |                             if (ed[w][z] + ed[w][y] == 1)
      |                             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 207 ms 652 KB Output is correct
8 Correct 205 ms 664 KB Output is correct
9 Correct 199 ms 2596 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 2584 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 7 ms 2396 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 17 ms 604 KB Output is correct
21 Correct 205 ms 2396 KB Output is correct
22 Correct 21 ms 600 KB Output is correct
23 Correct 103 ms 2392 KB Output is correct
24 Correct 31 ms 604 KB Output is correct
25 Correct 166 ms 604 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 4 ms 2396 KB Output is correct
31 Correct 173 ms 2596 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 166 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 207 ms 652 KB Output is correct
8 Correct 205 ms 664 KB Output is correct
9 Correct 199 ms 2596 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 2584 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 7 ms 2396 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 17 ms 604 KB Output is correct
21 Correct 205 ms 2396 KB Output is correct
22 Correct 21 ms 600 KB Output is correct
23 Correct 103 ms 2392 KB Output is correct
24 Correct 31 ms 604 KB Output is correct
25 Correct 166 ms 604 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 4 ms 2396 KB Output is correct
31 Correct 173 ms 2596 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 166 ms 668 KB Output is correct
34 Execution timed out 5014 ms 2936 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 207 ms 652 KB Output is correct
8 Correct 205 ms 664 KB Output is correct
9 Correct 199 ms 2596 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 2584 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 7 ms 2396 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 17 ms 604 KB Output is correct
21 Correct 205 ms 2396 KB Output is correct
22 Correct 21 ms 600 KB Output is correct
23 Correct 103 ms 2392 KB Output is correct
24 Correct 31 ms 604 KB Output is correct
25 Correct 166 ms 604 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 4 ms 2396 KB Output is correct
31 Correct 173 ms 2596 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 166 ms 668 KB Output is correct
34 Execution timed out 5014 ms 2936 KB Time limit exceeded
35 Halted 0 ms 0 KB -