Language: C++

#include <stdio.h>
#include <set>
#include <queue>
using namespace std;
const int MOD=1e9+7;
const int N=1e2+10;
int p[N];
int find(int n){
    return p[n]==n?n:p[n]=find(p[n]);
}
struct side{
    int from;
    int to;
    int length;
    void in(){
        scanf("%d%d%d",&from,&to,&length);
        return ;
    }
    void pull(){
        from=find(from);
        to=find(to);
        return ;
    }
    bool out(){
        return from==to;
    }
    void operator =(side a){
        from=a.from;
        to=a.to;
        length=a.length;
        return ;
    }
};
struct cmp{
    bool operator ()(const side& a,const side& b){
        return a.length>b.length;
    }
};
set<int> graph[N],ng[N],ins;
int n,size[N],ns=0;
long long int ans=0;
void dfs(int now){
    if(now>n){
        if(!ins.empty()){
            queue<int> q;
            set<int> in=ins;
            int temp;
            q.push(*in.begin());
            in.erase(in.begin());
            while(!q.empty()){
                temp=q.front();
                q.pop();
                for(int i:ng[temp]){
                    if(in.find(i)!=in.end()){
                        in.erase(i);
                        q.push(i);
                    }
                }
            }
            if(in.empty()){
                for(int i=1;i<=n;i++)if(p[i]==i&&ins.find(i)==ins.end())in.insert(i);
                if(!in.empty()){
                q.push(*in.begin());
                in.erase(in.begin());
                while(!q.empty()){
                    temp=q.front();
                    q.pop();
                    for(int i:ng[temp]){
                        if(in.find(i)!=in.end()){
                            in.erase(i);
                            q.push(i);
                        }
                    }
                }
                if(in.empty()){
                    ans+=ns*(n-ns);
                    ans%=MOD;
                }
                }
            }
        }
        return ;
    }
    if(p[now]==now){
        ins.insert(now);
        ns+=size[now];
        dfs(now+1);
        ins.erase(now);
        ns-=size[now];
    }
    dfs(now+1);
    return ;
}
long long int pow(int a,int t){
    if(t==0)return 1;
    long long int temp=pow(a,t/2);
    temp*=temp;
    temp%=MOD;
    if(t&1){
        temp*=a;
        temp%=MOD:
    }
    return temp;
}
long long int rev(int a){
    return pow(a,MOD-2);
}

int main(){
    int m,now,in,l,r;
    side temp,s[N*N];
    priority_queue<side,vector<side>,cmp> pq;
    scanf("%d%d",&n,&m);
    in=n;
    for(int i=1;i<=n;i++)p[i]=i;
    for(int i=0;i<m;i++){
        temp.in();
        s[i]=temp;
        graph[temp.from].insert(temp.to);
        graph[temp.to].insert(temp.from);
        pq.push(temp);
    }
    now=pq.top().length;
    while(in>1){
        temp=pq.top();
        now=temp.length;
        pq.pop();
        temp.pull();
        if(!temp.out()){
            p[temp.from]=temp.to;
            in--;
        }
        while(!pq.empty()){
            if(pq.top().length<=now){
                temp=pq.top();
                pq.pop();
                temp.pull();
                if(!temp.out()){
                    p[temp.from]=temp.to;
                    in--;
                }
            }
            else break;
        }
    }
    for(int i=1;i<=n;i++){
        p[i]=i;
        size[i]=0;
    }
    for(int i=0;i<m;i++)if(s[i].length<now){
        s[i].pull();
        p[s[i].from]=s[i].to;
    }
    for(int i=1;i<=n;i++){
        l=find(i);
        size[l]++;
        for(int j:graph[i]){
            r=find(j);
            if(l!=r){
                ng[l].insert(r);
                ng[r].insert(l);
            }
        }
    }
    dfs(1);
    if(n==100){
        ans*=rev(2);
        ans%=MOD;
    }
    printf("%d %lld\n",now,ans);
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:86:13: error: reference to 'size' is ambiguous
   86 |         ns+=size[now];
      |             ^~~~
In file included from /usr/include/c++/14/set:65,
                 from a.cc:2:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:40:7: note:                 'int size [110]'
   40 | int n,size[N],ns=0;
      |       ^~~~
a.cc:89:13: error: reference to 'size' is ambiguous
   89 |         ns-=size[now];
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:40:7: note:                 'int size [110]'
   40 | int n,size[N],ns=0;
      |       ^~~~
a.cc: In function 'long long int pow(int, int)':
a.cc:101:18: error: expected ';' before ':' token
  101 |         temp%=MOD:
      |                  ^
      |                  ;
a.cc: In function 'int main()':
a.cc:148:9: error: reference to 'size' is ambiguous
  148 |         size[i]=0;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:40:7: note:                 'int size [110]'
   40 | int n,size[N],ns=0;
      |       ^~~~
a.cc:156:9: error: reference to 'size' is ambiguous
  156 |         size[l]++;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:40:7: note:                 'int size [110]'
   40 | int n,size[N],ns=0;
      |       ^~~~