Submission #217538

#TimeUsernameProblemLanguageResultExecution timeMemory
217538arnold518Teleporters (IOI08_teleporters)C++14
100 / 100
999 ms48336 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 adj[MAXN+10]; bool vis[MAXN+10]; 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()); memset(adj, -1, sizeof(adj)); 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(); adj[a]=b+1; adj[b]=a+1; } vector<int> PQ; int now=0, sz=0; while(now!=-1) { sz++; vis[now]=true; now=adj[now]; } int ans=sz; for(i=0; i<=2*N; i++) { if(vis[i]) continue; now=i; sz=0; while(!vis[now]) { sz++; vis[now]=true; now=adj[now]; } PQ.push_back(sz); } sort(PQ.begin(), PQ.end()); while(M--) { if(!PQ.empty()) ans+=PQ.back()+2, PQ.pop_back(); else ans++, PQ.push_back(1); } printf("%d\n", ans-1); }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:18:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
teleporters.cpp:20: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:21: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...