Submission #829644

# Submission time Handle Problem Language Result Execution time Memory
829644 2023-08-18T13:44:33 Z tolbi Duathlon (APIO18_duathlon) C++17
23 / 100
1000 ms 1048576 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define rev(x) reverse(x.begin(), x.end())
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define tol(bi) (1LL<<((int)(bi)))
#define endl '\n'
#define int long long
//mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#ifdef tolbi
#include "duathlon.h"
#endif
int solve(int n, vector<int> u, vector<int> v){
    vector<vector<int>> arr(n);
    for (int i = 0; i < u.size(); ++i)
    {
        arr[u[i]].push_back(v[i]);
        arr[v[i]].push_back(u[i]);
    }
    vector<int> subsz(n);
    int ans = 0;
    auto f = [&](int node, int lnode, auto f)->void{
        subsz[node]=1;
        for (int i = 0; i < arr[node].size(); i++){
            if (arr[node][i]==lnode) continue;
            f(arr[node][i],node,f);
            subsz[node]+=subsz[arr[node][i]];
            ans+=(n-subsz[arr[node][i]]-1)*subsz[arr[node][i]];
        }
        ans+=(subsz[node]-1)*(n-subsz[node]);
    };
    f(0,-1,f);
    return ans;
}
int32_t main(){
	int T = 1;
	int tno = 0;
	while (T-(tno++)){
        deci(n);deci(m);
        vector<int> par(n);
        iota(par.begin(), par.end(), 0);
        function<int(int)> find;
        find = [&](int node)->int{
        	if (par[node]==node) return node;
        	return par[node]=find(par[node]);
        };
        vector<pair<int,int>> edges(m);
        for (int i = 0; i < m; i++){
        	cin>>edges[i].first>>edges[i].second;
        	edges[i].first--,edges[i].second--;
        	int u = edges[i].first;
        	int v = edges[i].second;
        	u=find(u);
        	v=find(v);
        	par[u]=v;
        }
        map<int,int> mp;
        map<int,vector<int>> u;
        map<int,vector<int>> v;
        vector<int> indis(n);
        for (int i = 0; i < n; i++){
        	indis[i]=mp[find(i)]++;
        }
        for (int i = 0; i < m; i++){
        	u[find(edges[i].first)].push_back(indis[edges[i].first]);
        	v[find(edges[i].second)].push_back(indis[edges[i].second]);
        }
        int ans = 0;
        for (auto it : mp){
        	ans+=solve(it.second,u[it.first],v[it.first]);
        }
        cout<<ans<<endl;
	}
}

Compilation message

count_triplets.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
count_triplets.cpp: In function 'long long int solve(long long int, std::vector<long long int>, std::vector<long long int>)':
count_triplets.cpp:30:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < u.size(); ++i)
      |                     ~~^~~~~~~~~~
count_triplets.cpp: In instantiation of 'solve(long long int, std::vector<long long int>, std::vector<long long int>)::<lambda(long long int, long long int, auto:23)> [with auto:23 = solve(long long int, std::vector<long long int>, std::vector<long long int>)::<lambda(long long int, long long int, auto:23)>]':
count_triplets.cpp:47:13:   required from here
count_triplets.cpp:39:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i < arr[node].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 487 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 487 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 828996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 13556 KB Output is correct
2 Correct 75 ms 14256 KB Output is correct
3 Correct 80 ms 14392 KB Output is correct
4 Correct 70 ms 14320 KB Output is correct
5 Correct 70 ms 14216 KB Output is correct
6 Correct 77 ms 16972 KB Output is correct
7 Correct 77 ms 16408 KB Output is correct
8 Correct 73 ms 15756 KB Output is correct
9 Correct 90 ms 15300 KB Output is correct
10 Correct 70 ms 10656 KB Output is correct
11 Correct 71 ms 13668 KB Output is correct
12 Correct 67 ms 9020 KB Output is correct
13 Correct 89 ms 8604 KB Output is correct
14 Correct 112 ms 9028 KB Output is correct
15 Correct 104 ms 10764 KB Output is correct
16 Correct 89 ms 16080 KB Output is correct
17 Correct 76 ms 16148 KB Output is correct
18 Correct 76 ms 15560 KB Output is correct
19 Correct 69 ms 16136 KB Output is correct
20 Correct 87 ms 15152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Runtime error 543 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 13624 KB Output is correct
2 Correct 72 ms 14572 KB Output is correct
3 Runtime error 777 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 487 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 487 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -