제출 #1129741

#제출 시각아이디문제언어결과실행 시간메모리
1129741PieArmy조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2)C++20
0 / 100
15 ms19008 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} int n,m; set<int>gel[100001],git[100001],gel2[100001],st[100001]; int par[100001]; ll siz[100001],ans=0; vector<pair<int,int>>v; int get(int x){ if(x==par[x])return x; return par[x]=get(par[x]); } void add(int a,int b){ git[a].insert(b); gel[b].insert(a); gel2[b].insert(a); if(git[b].find(a)!=git[b].end()){ v.pb({a,b}); } } void unite(int x,int y){ x=get(x);y=get(y); if(x==y)return; if(siz[x]+gel[x].size()+git[x].size()+gel2[x].size()<siz[y]+gel[y].size()+git[y].size()+gel2[y].size())swap(x,y); ans+=siz[x]*siz[y]*2+siz[x]*ll(gel2[y].size())+siz[y]*ll(gel2[x].size()); for(int a:gel2[y]){ if(get(a)==x){ ans-=siz[y]+siz[x]; } else if(gel2[x].find(a)!=gel2[x].end()){ ans-=siz[y]+siz[x]; } else gel2[x].insert(a); } for(int a:st[y]){ if(gel2[x].find(a)!=gel2[x].end()){ ans-=siz[y]+siz[x]; gel2[x].erase(a); } st[x].insert(a); } for(int a:gel[y]){ git[a].erase(y); add(a,x); } for(int a:git[y]){ gel[a].erase(y); add(x,a); } st[y].clear(); gel2[y].clear(); gel[y].clear(); git[y].clear(); par[y]=x; siz[x]+=siz[y]; } void code(){ cin>>n>>m; for(int i=1;i<=n;i++){ siz[i]=1; par[i]=i; st[i].insert(i); } while(m--){ int a,b;cin>>a>>b; b=get(b); if(get(a)!=b&&gel2[b].find(a)==gel2[b].end()){ a=get(a); ans+=siz[b]; add(a,b); } while(v.size()){ unite(v.back().fr,v.back().sc); v.pop_back(); } cout<<ans<<endl; } } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();} return 0; }

컴파일 시 표준 에러 (stderr) 메시지

joitter2.cpp: In function 'int main()':
joitter2.cpp:96:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~
joitter2.cpp:96:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...