이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define ld long double
#define chad char
#define mod 666'013
#define dim 100005
#define lim 1000000
#define BASE 31
#define NMAX 21'005
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define nr_biti __builtin_popcount
using namespace __gnu_pbds;
using namespace std;
ifstream fin("b.in");
ofstream fout("b.out");
int t=1;
ll n,m;
vector<int> g[dim];
ll ans;
ll sz[dim];
bool viz[dim];
void dfs(int nod,int daddy=0)
{
sz[nod]=1;
viz[nod]=1;
for(auto it:g[nod])
{
if(it==daddy)
continue;
dfs(it,nod);
sz[nod]+=sz[it];
}
ans+=(2LL*(sz[nod]-1)*(n-sz[nod]));
for(auto it:g[nod])
{
if(it==daddy)
continue;
ans+=(sz[it]*(sz[nod]-1-sz[it]));
}
}
void solve()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
int x,y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i=1; i<=n; i++)
{
if(!viz[i])
dfs(i);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//cin >> t;
while(t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |