Submission #259786

# Submission time Handle Problem Language Result Execution time Memory
259786 2020-08-08T14:34:05 Z Kastanda Making Friends on Joitter is Fun (JOI20_joitter2) C++11
100 / 100
1545 ms 92424 KB
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, P[N];
long long tot;
set < int > In[N], Out[N], Fin[N];
set < pair < int , int > > Fout[N];
vector < pair < int , int > > Edges[N];
queue < pair < int , int > > E;
int Find(int v)
{
        return (P[v] < 0 ? v : (P[v] = Find(P[v])));
}
inline void Merge(int v, int u)
{
        if (Edges[v].size() < Edges[u].size())
                swap(v, u);

        //printf("%d :::: %d\n", v, u);
        tot -= (-P[u]) * 1LL * (int)Fin[u].size();
        tot += (-P[u]) * 1LL * (int)Fin[v].size();
        for (int a : Fin[u])
                Fout[Find(a)].erase({u, a});
        Fin[u].clear();
        for (auto a : Fout[u])
        {
                tot -= -P[a.first];
                Fin[a.first].erase(a.second);
                if (a.first == v)
                        tot -= -P[u];
        }
        Fout[u].clear();

        for (auto X : Edges[u])
                E.push(X);//, printf("%d , %d\n", X.first, X.second), fflush(stdout);
        Edges[u].clear();

        In[u].clear();
        Out[u].clear();

        tot += P[v] * 2LL * P[u];
        P[v] += P[u];
        P[u] = v;
}
int main()
{
        scanf("%d%d", &n, &m);
        memset(P, -1, sizeof(P));
        for (int i = 1; i <= m; i ++)
        {
                int a, b;
                scanf("%d%d", &a, &b);
                E.push({a, b});
                /*if (i >= 6)
                        printf("%d =====\n", i);
                fflush(stdout);*/
                while (E.size())
                {
                        /*if (i == 7)
                                printf("|| %lld  ||\n", tot);*/
                        int v = E.front().first;
                        int u = E.front().second;
                        E.pop();
                        int pv = Find(v);
                        int pu = Find(u);
                        if (pv == pu)
                                continue;
                        if (!Out[pu].count(pv))
                        {
                                if (Fout[pv].count({pu, v}))
                                        continue;
                                Edges[pv].push_back(make_pair(v, u));
                                Edges[pu].push_back(make_pair(v, u));
                                Fout[pv].insert({pu, v});
                                Fin[pu].insert(v);
                                Out[pv].insert(pu);
                                In[pu].insert(pv);
                                tot += -P[pu];
                                continue;
                        }
                        Merge(pv, pu);
                }
                printf("%lld\n", tot);
        }
        return 0;
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &n, &m);
         ~~~~~^~~~~~~~~~~~~~~~
joitter2.cpp:53:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d%d", &a, &b);
                 ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21888 KB Output is correct
2 Correct 13 ms 21888 KB Output is correct
3 Correct 15 ms 21888 KB Output is correct
4 Correct 13 ms 21888 KB Output is correct
5 Correct 13 ms 21888 KB Output is correct
6 Correct 14 ms 21888 KB Output is correct
7 Correct 14 ms 21888 KB Output is correct
8 Correct 14 ms 21888 KB Output is correct
9 Correct 15 ms 21888 KB Output is correct
10 Correct 13 ms 21888 KB Output is correct
11 Correct 14 ms 21888 KB Output is correct
12 Correct 14 ms 21888 KB Output is correct
13 Correct 13 ms 21888 KB Output is correct
14 Correct 13 ms 21888 KB Output is correct
15 Correct 14 ms 22016 KB Output is correct
16 Correct 13 ms 21888 KB Output is correct
17 Correct 13 ms 21888 KB Output is correct
18 Correct 13 ms 21888 KB Output is correct
19 Correct 13 ms 21888 KB Output is correct
20 Correct 16 ms 21888 KB Output is correct
21 Correct 16 ms 21920 KB Output is correct
22 Correct 14 ms 21888 KB Output is correct
23 Correct 13 ms 21888 KB Output is correct
24 Correct 14 ms 21888 KB Output is correct
25 Correct 14 ms 21888 KB Output is correct
26 Correct 13 ms 21888 KB Output is correct
27 Correct 13 ms 21888 KB Output is correct
28 Correct 13 ms 21888 KB Output is correct
29 Correct 13 ms 21920 KB Output is correct
30 Correct 13 ms 21888 KB Output is correct
31 Correct 14 ms 21888 KB Output is correct
32 Correct 13 ms 21888 KB Output is correct
33 Correct 14 ms 21888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21888 KB Output is correct
2 Correct 13 ms 21888 KB Output is correct
3 Correct 15 ms 21888 KB Output is correct
4 Correct 13 ms 21888 KB Output is correct
5 Correct 13 ms 21888 KB Output is correct
6 Correct 14 ms 21888 KB Output is correct
7 Correct 14 ms 21888 KB Output is correct
8 Correct 14 ms 21888 KB Output is correct
9 Correct 15 ms 21888 KB Output is correct
10 Correct 13 ms 21888 KB Output is correct
11 Correct 14 ms 21888 KB Output is correct
12 Correct 14 ms 21888 KB Output is correct
13 Correct 13 ms 21888 KB Output is correct
14 Correct 13 ms 21888 KB Output is correct
15 Correct 14 ms 22016 KB Output is correct
16 Correct 13 ms 21888 KB Output is correct
17 Correct 13 ms 21888 KB Output is correct
18 Correct 13 ms 21888 KB Output is correct
19 Correct 13 ms 21888 KB Output is correct
20 Correct 16 ms 21888 KB Output is correct
21 Correct 16 ms 21920 KB Output is correct
22 Correct 14 ms 21888 KB Output is correct
23 Correct 13 ms 21888 KB Output is correct
24 Correct 14 ms 21888 KB Output is correct
25 Correct 14 ms 21888 KB Output is correct
26 Correct 13 ms 21888 KB Output is correct
27 Correct 13 ms 21888 KB Output is correct
28 Correct 13 ms 21888 KB Output is correct
29 Correct 13 ms 21920 KB Output is correct
30 Correct 13 ms 21888 KB Output is correct
31 Correct 14 ms 21888 KB Output is correct
32 Correct 13 ms 21888 KB Output is correct
33 Correct 14 ms 21888 KB Output is correct
34 Correct 17 ms 22016 KB Output is correct
35 Correct 152 ms 28412 KB Output is correct
36 Correct 175 ms 32120 KB Output is correct
37 Correct 172 ms 32248 KB Output is correct
38 Correct 175 ms 31736 KB Output is correct
39 Correct 16 ms 22144 KB Output is correct
40 Correct 17 ms 22272 KB Output is correct
41 Correct 17 ms 22144 KB Output is correct
42 Correct 16 ms 22016 KB Output is correct
43 Correct 17 ms 22272 KB Output is correct
44 Correct 18 ms 22144 KB Output is correct
45 Correct 17 ms 22144 KB Output is correct
46 Correct 16 ms 22016 KB Output is correct
47 Correct 18 ms 22272 KB Output is correct
48 Correct 18 ms 22208 KB Output is correct
49 Correct 30 ms 23424 KB Output is correct
50 Correct 189 ms 32504 KB Output is correct
51 Correct 29 ms 22648 KB Output is correct
52 Correct 155 ms 29936 KB Output is correct
53 Correct 27 ms 23296 KB Output is correct
54 Correct 168 ms 31096 KB Output is correct
55 Correct 22 ms 22784 KB Output is correct
56 Correct 24 ms 22784 KB Output is correct
57 Correct 22 ms 22784 KB Output is correct
58 Correct 22 ms 22784 KB Output is correct
59 Correct 17 ms 22016 KB Output is correct
60 Correct 146 ms 27000 KB Output is correct
61 Correct 23 ms 22272 KB Output is correct
62 Correct 185 ms 31480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21888 KB Output is correct
2 Correct 13 ms 21888 KB Output is correct
3 Correct 15 ms 21888 KB Output is correct
4 Correct 13 ms 21888 KB Output is correct
5 Correct 13 ms 21888 KB Output is correct
6 Correct 14 ms 21888 KB Output is correct
7 Correct 14 ms 21888 KB Output is correct
8 Correct 14 ms 21888 KB Output is correct
9 Correct 15 ms 21888 KB Output is correct
10 Correct 13 ms 21888 KB Output is correct
11 Correct 14 ms 21888 KB Output is correct
12 Correct 14 ms 21888 KB Output is correct
13 Correct 13 ms 21888 KB Output is correct
14 Correct 13 ms 21888 KB Output is correct
15 Correct 14 ms 22016 KB Output is correct
16 Correct 13 ms 21888 KB Output is correct
17 Correct 13 ms 21888 KB Output is correct
18 Correct 13 ms 21888 KB Output is correct
19 Correct 13 ms 21888 KB Output is correct
20 Correct 16 ms 21888 KB Output is correct
21 Correct 16 ms 21920 KB Output is correct
22 Correct 14 ms 21888 KB Output is correct
23 Correct 13 ms 21888 KB Output is correct
24 Correct 14 ms 21888 KB Output is correct
25 Correct 14 ms 21888 KB Output is correct
26 Correct 13 ms 21888 KB Output is correct
27 Correct 13 ms 21888 KB Output is correct
28 Correct 13 ms 21888 KB Output is correct
29 Correct 13 ms 21920 KB Output is correct
30 Correct 13 ms 21888 KB Output is correct
31 Correct 14 ms 21888 KB Output is correct
32 Correct 13 ms 21888 KB Output is correct
33 Correct 14 ms 21888 KB Output is correct
34 Correct 17 ms 22016 KB Output is correct
35 Correct 152 ms 28412 KB Output is correct
36 Correct 175 ms 32120 KB Output is correct
37 Correct 172 ms 32248 KB Output is correct
38 Correct 175 ms 31736 KB Output is correct
39 Correct 16 ms 22144 KB Output is correct
40 Correct 17 ms 22272 KB Output is correct
41 Correct 17 ms 22144 KB Output is correct
42 Correct 16 ms 22016 KB Output is correct
43 Correct 17 ms 22272 KB Output is correct
44 Correct 18 ms 22144 KB Output is correct
45 Correct 17 ms 22144 KB Output is correct
46 Correct 16 ms 22016 KB Output is correct
47 Correct 18 ms 22272 KB Output is correct
48 Correct 18 ms 22208 KB Output is correct
49 Correct 30 ms 23424 KB Output is correct
50 Correct 189 ms 32504 KB Output is correct
51 Correct 29 ms 22648 KB Output is correct
52 Correct 155 ms 29936 KB Output is correct
53 Correct 27 ms 23296 KB Output is correct
54 Correct 168 ms 31096 KB Output is correct
55 Correct 22 ms 22784 KB Output is correct
56 Correct 24 ms 22784 KB Output is correct
57 Correct 22 ms 22784 KB Output is correct
58 Correct 22 ms 22784 KB Output is correct
59 Correct 17 ms 22016 KB Output is correct
60 Correct 146 ms 27000 KB Output is correct
61 Correct 23 ms 22272 KB Output is correct
62 Correct 185 ms 31480 KB Output is correct
63 Correct 816 ms 92352 KB Output is correct
64 Correct 845 ms 92424 KB Output is correct
65 Correct 871 ms 92408 KB Output is correct
66 Correct 291 ms 34920 KB Output is correct
67 Correct 479 ms 40512 KB Output is correct
68 Correct 274 ms 34920 KB Output is correct
69 Correct 557 ms 40428 KB Output is correct
70 Correct 280 ms 34924 KB Output is correct
71 Correct 341 ms 35088 KB Output is correct
72 Correct 641 ms 40952 KB Output is correct
73 Correct 658 ms 40952 KB Output is correct
74 Correct 1545 ms 68444 KB Output is correct
75 Correct 846 ms 48328 KB Output is correct
76 Correct 1180 ms 61036 KB Output is correct
77 Correct 1260 ms 61104 KB Output is correct
78 Correct 347 ms 41068 KB Output is correct
79 Correct 665 ms 45672 KB Output is correct
80 Correct 365 ms 40812 KB Output is correct
81 Correct 468 ms 44144 KB Output is correct
82 Correct 1081 ms 69844 KB Output is correct
83 Correct 1088 ms 69980 KB Output is correct
84 Correct 940 ms 70000 KB Output is correct
85 Correct 971 ms 69904 KB Output is correct
86 Correct 234 ms 31608 KB Output is correct
87 Correct 285 ms 33852 KB Output is correct
88 Correct 544 ms 41312 KB Output is correct
89 Correct 1120 ms 59260 KB Output is correct