Submission #509906

#TimeUsernameProblemLanguageResultExecution timeMemory
509906leinad2Making Friends on Joitter is Fun (JOI20_joitter2)C++17
0 / 100
3 ms4940 KiB
#include<bits/stdc++.h> using namespace std; int n, m, i, j, k, a, b, sz[100010], indeg[100010], par[100010]; long long ans; int Find(int v){return v==par[v]?v:par[v]=Find(par[v]);} map<int, set<int> >adj[100010]; main() { scanf("%d %d", &n, &m); for(i=0;i++<n;)sz[i]=1,par[i]=i; while(m--) { scanf("%d %d", &a, &b); int x=a, y=b; a=Find(a);b=Find(b); if(a!=b) { if(adj[a].find(b)==adj[a].end()) { if(adj[b][a].find(x)==adj[b][a].end()) { adj[b][a].insert(x); ans+=sz[b]; indeg[b]++; } } else { ans-=1LL*(indeg[a]-(int)adj[a][b].size())*sz[a]; ans-=1LL*(indeg[b])*sz[b]; ans+=1LL*sz[a]*sz[b]; ans+=1LL*(sz[b]-adj[a][b].size())*sz[a]; if(indeg[a]<indeg[b])swap(adj[a], adj[b]); for(auto p:adj[b]) { for(auto q:p.second) adj[a][p.first].insert(q); } adj[b].clear(); indeg[a]-=adj[a][b].size(); adj[a].erase(b); sz[a]+=sz[b]; indeg[a]+=indeg[b]; par[b]=a; ans+=1LL*indeg[a]*sz[a]; } } printf("%lld\n", ans); } }

Compilation message (stderr)

joitter2.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~
joitter2.cpp: In function 'int main()':
joitter2.cpp:14:18: warning: unused variable 'y' [-Wunused-variable]
   14 |         int x=a, y=b;
      |                  ^
joitter2.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
joitter2.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...