Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- #define ff first
- #define ss second
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define dbg(x) cerr<<" "<<#x<<" "<<x<<endl
- typedef long long ll;
- using namespace std;
- const int inf = 1e8 + 7;
- const int maxn = 3e5 + 13;
- vector <int> gr[maxn];
- struct edge {
- int u, cnt, idx;
- };
- bool cmp (const edge &a, const edge &b) {
- return a.cnt < b.cnt;
- }
- int main() {
- FASTER();
- int n, m;
- cin >> n >> m;
- vector <int> order(n, inf);
- vector <edge> vertexes(n, {inf, inf});
- for(int i = 0; i < m; i++) {
- int u, v;
- cin >> u >> v;
- u--; v--;
- gr[u].pb(v);
- vertexes[u].u = u;
- vertexes[u].cnt++;
- gr[v].pb(u);
- vertexes[v].u = v;
- vertexes[v].cnt++;
- }
- sort(all(vertexes), cmp);
- for(int i = 0; i < n; i++) {
- if(vertexes[i].u == inf) {
- continue;
- }
- order[vertexes[i].u] = i;
- }
- vector <int> c(n, 0);
- int ans = 0;
- for(auto a : vertexes) {
- int i = a.u;
- if(i == inf) {
- continue;
- }
- for(int j : gr[i]) {
- c[j]++;
- }
- for(auto j : gr[i]) {
- if(order[j] > order[i]) {
- for (auto k : gr[j]) {
- if(order[k] > order[j]) {
- ans += c[k];
- }
- }
- }
- }
- for(int j : gr[i]) {
- c[j]--;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment