// Author : Thao Nguyen Xinh
// Codeforces Handle : thaonguyendethuongvai
// Greedy problem
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define endl "\n"
#define pair pair< tn, tn >
#define tn long long
#define thaonguyen( i, a, b ) for( tn i = a; i <= b; i++ )
#define nguyenthao( i, a, b ) for( tn i = a; i >= b; i-- )
#define thaonguyenxinh ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const tn N = 1e5 + 5;
bool ed[N];
set< pair > st;
vector<tn> g[N];
vector<pair> vertex;
tn n, m, u, v, cur_result, cur_min, par[N], sz[N], result = -1, deg[N];
tn acs( tn u ){
return u == par[u] ? u : par[u] = acs( par[u] );
}
void join( tn u, tn v ){
tn x = acs(u);
tn y = acs(v);
if ( sz[x] < sz[y] )
swap( x, y );
if ( x != y ){
par[x] = y;
sz[y] += sz[x];
}
result = max( result, cur_min * sz[y] );
}
signed main(){
thaonguyenxinh
freopen( "thao_nguyen_trong_tim_toan.inp", "r", stdin );
freopen( "thao_nguyen_trong_tim_toan.out", "w", stdout );
cin >> n >> m;
thaonguyen( i, 1, n )
par[i] = i,
sz[i] = 1;
thaonguyen( i, 1, m )
cin >> u >> v,
g[u].push_back(v),
g[v].push_back(u),
deg[u]++, deg[v]++;
thaonguyen( i, 1, n )
st.insert( { deg[i], i } );
while ( !st.empty() ){
pair cur = *st.begin();
for ( auto v : g[cur.se] ){
pair temp = { deg[v], v };
if ( st.find( temp ) != st.end() ){
st.erase( st.find( temp ) );
deg[v]--;
st.insert( { deg[v], v } );
}
}
vertex.push_back( { cur.se, cur.fi } );
st.erase( st.find(cur) );
}
reverse( vertex.begin(), vertex.end() );
for ( auto u : vertex ){
cur_min = u.se;
ed[u.fi] = true;
for ( auto v : g[u.fi] )
if ( ed[v] )
join( u.fi, v );
}
cout << result;
}
Compilation message (stderr)
park.cpp: In function 'int main()':
park.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen( "thao_nguyen_trong_tim_toan.inp", "r", stdin );
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen( "thao_nguyen_trong_tim_toan.out", "w", stdout );
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |