Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1.  
  2.  
  3. Skip to content
  4. Using Free University Tbilisi Mail with screen readers
  5.  
  6. 1 of 5,550
  7. (no subject)
  8. Inbox
  9. x
  10.  
  11. Zuka Kenchuashvili
  12. Attachments
  13. 5:07 PM (0 minutes ago)
  14. to me
  15.  
  16.  
  17. Attachments area
  18.  
  19.  
  20. Compose:
  21. New Message
  22. MinimizePop-outClose
  23. To
  24. elsamziuri@gmail.com
  25. elsamziuri@gmail.com
  26. elzamziuri@gmail.com
  27. Subject
  28.  
  29.  
  30. --
  31. დავით ბეჟანიშვილი
  32. მათემატიკისა და კომპიუტერული მეცნიერების სკოლის სტუდენტი
  33. #include <bits/stdc++.h>
  34. using namespace std;
  35. int n,m,a[100001],b[100001],i,e,z,t,x,y,w,c;
  36. bool fix[100001];
  37. map <int , int> ma[100001];
  38. void dfs(int v){
  39.     int k;
  40.     k=1;
  41.     fix[v]=1;
  42.     for(int j=1;j<=t;j++){
  43.         if(ma[v][b[k]]==0 && v!=b[k]){
  44.             swap(b[k],b[t]);
  45.             t=t-1;
  46.             dfs(b[t+1]);
  47.         }
  48.         else
  49.         k++;
  50.         if(k==t+1){
  51.             break ;
  52.         }
  53.     }
  54. }
  55.  
  56.  
  57. int main(){
  58.     cin>>n>>m;
  59.     for(i=1;i<=m;i++){
  60.         cin>>x>>y;
  61.         ma[x][y]=1;
  62.         ma[y][x]=1;
  63.         a[x]=a[x]+1;
  64.         a[y]=a[y]+1;
  65.     }
  66.     b[1]=1;
  67.     t=n;
  68.     for(i=2;i<=n;i++){
  69.         b[i]=b[i-1]+1;
  70.     }
  71.     for(i=1;i<=n;i++){
  72.         if(fix[i]==0 && a[i]<n-1){
  73.             dfs(i);
  74.             c++;
  75.         }
  76.     }
  77.    
  78.     for(i=1;i<=n;i++){
  79.         if(a[i]<n-1){
  80.             z++;
  81.         }
  82.     }
  83.     e=n*(n-1)/2-m;
  84.     w=n*(n-1)/2-n+1;
  85.     if(e==z-c){
  86.         if(w>=m){
  87.             cout<<0<<endl;
  88.         }
  89.         else
  90.         cout<<m-w<<endl;
  91.         return 0;
  92.     }
  93.     if(w<=e-z+c){
  94.         cout<<m<<endl;
  95.         return 0;
  96.     }
  97.     w=w-e+z-c;
  98.     if(w>=m){
  99.         cout<<0<<endl;
  100.     }
  101.     else
  102.     cout<<m-w<<endl;
  103.     return 0;
  104.    
  105. }
  106. 0-1.cpp
  107. Displaying 0-1.cpp.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement