제출 #217535

#제출 시각아이디문제언어결과실행 시간메모리
217535arnold518Teleporters (IOI08_teleporters)C++14
90 / 100
1098 ms33488 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e6; int N, M; pii A[MAXN+10]; int par[MAXN+10], sz[MAXN+10]; int Find(int x) { return x==par[x] ? x : par[x]=Find(par[x]); } void Union(int x, int y) { x=Find(x); y=Find(y); if(x==y) return; if(sz[x]>sz[y]) swap(x, y); par[x]=y; sz[y]+=sz[x]; } int main() { int i, j; scanf("%d%d", &N, &M); for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second); vector<int> comp; for(i=1; i<=N; i++) comp.push_back(A[i].first), comp.push_back(A[i].second); sort(comp.begin(), comp.end()); for(i=0; i<=2*N; i++) par[i]=i, sz[i]=1; for(i=1; i<=N; i++) { int a=lower_bound(comp.begin(), comp.end(), A[i].first)-comp.begin(), b=lower_bound(comp.begin(), comp.end(), A[i].second)-comp.begin(); Union(a, b+1); Union(a+1, b); } priority_queue<int> PQ; for(i=0; i<=2*N; i++) if(par[i]==i && i!=Find(0)) PQ.push(sz[i]); int ans=sz[Find(0)]; while(M--) { if(!PQ.empty()) ans+=PQ.top()+2, PQ.pop(); else ans++, PQ.push(1); } printf("%d\n", ans-1); }

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

teleporters.cpp: In function 'int main()':
teleporters.cpp:25:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
teleporters.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
teleporters.cpp:28:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...