Codeforces 489D unbearable Controversy of Being

Source: Internet
Author: User

Test instructions

N (3000) points m (30000) edges of a simple graph statistics the number of diamonds drawn in the question

Ideas:

We can think of the diamond as two paths with a distance of 2 a->c and then assuming that we enumerate the number of path strips with a i->j distance of 2, we can calculate it with a simple combination number.

If the violent calculation of the number of paths is n^3, but we can use the distance of 2, we use the adjacency table and the adjacency matrix to enumerate all sides of the edge m at the same time by the adjacency table and then know that the i->k distance is 1 then we enumerate all n point adjacency matrix to determine if K->j has a road I-&G T;j path complexity of length 2 is O (nm)

Code:

#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath> #include <bitset>using namespace std; #define N 3010typedef long ll;int N, m;    LL ans;vector<int> ed[n];int Maz[n][n], F[n][n];int main () {scanf ("%d%d", &n, &m);        for (int i = 1; I <= m; i++) {int u, v;        scanf ("%d%d", &u, &v);        MAZ[U][V] = 1;    Ed[u].push_back (v); } for (int i = 1; I <= N, i++) {for (int j = 0; J < ed[i].size (); + j) {for (int k = 1; k &lt ; = N;            k++) {if (maz[ed[i][j]][k]) f[i][k]++; }}} for (int i = 1, i <= N; i++) {for (int j = 1; J <= N; j + +) {if (i! = J && Amp F[I][J] > 1) ans + = (LL) (F[i][j]-1) * F[i][j]/2;        printf ("%d%d%d\n", I, J, F[i][j]);    }} printf ("%i64d\n", ans); return 0;}


Codeforces 489D unbearable Controversy of Being

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.