답안 #341354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341354 2020-12-29T14:27:57 Z beksultan04 관광지 (IZhO14_shymbulak) C++14
0 / 100
47 ms 47980 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e6+12,INF=1e9+7;

vector <int> g[N],cycle,v;
pii ver[N];
bool bosh[N],vis[N];
void dfs_cycle(int x,int p){
    vis[x] = 1;
    int i,j;
    v.pb(x);
    for (i=0;i<g[x].size();++i){
        int to = g[x][i];
        if (vis[to] == 1 && to != p){
            bool f=0;
            for (j=0;j<v.size();++j){
                if (v[j] == to)f=1;
                if (f){
                    cycle.pb(v[j]);
                }

            }
        }
        if (vis[to] == 0){
            dfs_cycle(to,x);
        }
    }
    v.pop_back();
}

int dlina[N],colichestvo[N];

void dfs_diametr(int x,int p){
    int i;
    if (g[x].size() == 1){
        colichestvo[x] = 1;
        ret;
    }
    vector <pii> tmp;
    for (i=0;i<g[x].size();++i){
        if (g[x][i] == p || bosh[g[x][i]])continue;
        dfs_diametr(g[x][i],x);
        tmp.pb({dlina[g[x][i]],colichestvo[g[x][i]]});
    }
    if (tmp.size() == 0){
        colichestvo[x] = 1;
        ret;
    }
    sort(allr(tmp));
    int mx = tmp[0].fr,cnt = tmp[0].sc;
    for (i=1;i<tmp.size();++i){

        if (tmp[i].fr == mx){
            cnt += tmp[i].sc;
        }

    }
    dlina[x] = mx+1;
    colichestvo[x] = cnt;
}
int ans,cnt;

int calc(int x,int y,int m){
    int dist = min(abs(x-y),m-abs(x-y));
    dist += dlina[cycle[x]];
    dist += dlina[cycle[y]];
    if (ans < dist){
        ans = dist;
        cnt=0;
    }
    if (dist == ans){
        if (abs(x-y) == (m-abs(x-y))){
            cnt += max(colichestvo[cycle[x]],1ll)*max(1ll,colichestvo[cycle[y]])*2;
        }
        else
            cnt += colichestvo[cycle[x]]*colichestvo[cycle[y]];
    }
}


main(){

    int n,i,j;
    scan1(n)
    for (i=1;i<=n;++i){
        int x,y;
        scan2(x,y)
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs_cycle(1,0);

    int m = cycle.size();
    for (i=0;i<m;++i)
        bosh[cycle[i]] = 1;
    for (i=0;i<m;++i){
        dfs_diametr(cycle[i],0);
//        cout <<cycle[i]<<"-"<<dlina[cycle[i]]<<" ";
//        cout <<colichestvo[cycle[i]]<<"\n";
    }

    for (i=0;i<m;++i){
        for (j=i+1;j<m;++j){
            calc(i,j,m);
        }
    }
    cout <<cnt;


}

Compilation message

shymbulak.cpp: In function 'void dfs_cycle(long long int, long long int)':
shymbulak.cpp:32:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (j=0;j<v.size();++j){
      |                      ~^~~~~~~~~
shymbulak.cpp: In function 'void dfs_diametr(long long int, long long int)':
shymbulak.cpp:60:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp:71:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (i=1;i<tmp.size();++i){
      |              ~^~~~~~~~~~~
shymbulak.cpp: In function 'long long int calc(long long int, long long int, long long int)':
shymbulak.cpp:98:1: warning: no return statement in function returning non-void [-Wreturn-type]
   98 | }
      | ^
shymbulak.cpp: At global scope:
shymbulak.cpp:101:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main(){
      |      ^
shymbulak.cpp: In function 'int main()':
shymbulak.cpp:14:24: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   14 | #define scan1(a) scanf("%d",&a);
      |                        ^~~~ ~~~~
      |                             |
      |                             long long int*
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~    
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~  
   22 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~       
   23 | const int N = 1e6+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24 | 
      |                         
   25 | vector <int> g[N],cycle,v;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | pii ver[N];
      | ~~~~~~~~~~~             
   27 | bool bosh[N],vis[N];
      | ~~~~~~~~~~~~~~~~~~~~    
   28 | void dfs_cycle(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     vis[x] = 1;
      |     ~~~~~~~~~~~         
   30 |     int i,j;
      |     ~~~~~~~~            
   31 |     v.pb(x);
      |     ~~~~~~~~            
   32 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   33 |         int to = g[x][i];
      |         ~~~~~~~~~~~~~~~~~
   34 |         if (vis[to] == 1 && to != p){
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   35 |             bool f=0;
      |             ~~~~~~~~~   
   36 |             for (j=0;j<v.size();++j){
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                 if (v[j] == to)f=1;
      |                 ~~~~~~~~~~~~~~~~~~~
   38 |                 if (f){
      |                 ~~~~~~~ 
   39 |                     cycle.pb(v[j]);
      |                     ~~~~~~~~~~~~~~~
   40 |                 }
      |                 ~       
   41 | 
      |                         
   42 |             }
      |             ~           
   43 |         }
      |         ~               
   44 |         if (vis[to] == 0){
      |         ~~~~~~~~~~~~~~~~~~
   45 |             dfs_cycle(to,x);
      |             ~~~~~~~~~~~~~~~~
   46 |         }
      |         ~               
   47 |     }
      |     ~                   
   48 |     v.pop_back();
      |     ~~~~~~~~~~~~~       
   49 | }
      | ~                       
   50 | 
      |                         
   51 | int dlina[N],colichestvo[N];
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   52 | 
      |                         
   53 | void dfs_diametr(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   54 |     int i;
      |     ~~~~~~              
   55 |     if (g[x].size() == 1){
      |     ~~~~~~~~~~~~~~~~~~~~~~
   56 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   57 |         ret;
      |         ~~~~            
   58 |     }
      |     ~                   
   59 |     vector <pii> tmp;
      |     ~~~~~~~~~~~~~~~~~   
   60 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   61 |         if (g[x][i] == p || bosh[g[x][i]])continue;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   62 |         dfs_diametr(g[x][i],x);
      |         ~~~~~~~~~~~~~~~~~~~~~~~
   63 |         tmp.pb({dlina[g[x][i]],colichestvo[g[x][i]]});
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   64 |     }
      |     ~                   
   65 |     if (tmp.size() == 0){
      |     ~~~~~~~~~~~~~~~~~~~~~
   66 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   67 |         ret;
      |         ~~~~            
   68 |     }
      |     ~                   
   69 |     sort(allr(tmp));
      |     ~~~~~~~~~~~~~~~~    
   70 |     int mx = tmp[0].fr,cnt = tmp[0].sc;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71 |     for (i=1;i<tmp.size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 | 
      |                         
   73 |         if (tmp[i].fr == mx){
      |         ~~~~~~~~~~~~~~~~~~~~~
   74 |             cnt += tmp[i].sc;
      |             ~~~~~~~~~~~~~~~~~
   75 |         }
      |         ~               
   76 | 
      |                         
   77 |     }
      |     ~                   
   78 |     dlina[x] = mx+1;
      |     ~~~~~~~~~~~~~~~~    
   79 |     colichestvo[x] = cnt;
      |     ~~~~~~~~~~~~~~~~~~~~~
   80 | }
      | ~                       
   81 | int ans,cnt;
      | ~~~~~~~~~~~~            
   82 | 
      |                         
   83 | int calc(int x,int y,int m){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   84 |     int dist = min(abs(x-y),m-abs(x-y));
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   85 |     dist += dlina[cycle[x]];
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   86 |     dist += dlina[cycle[y]];
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   87 |     if (ans < dist){
      |     ~~~~~~~~~~~~~~~~    
   88 |         ans = dist;
      |         ~~~~~~~~~~~     
   89 |         cnt=0;
      |         ~~~~~~          
   90 |     }
      |     ~                   
   91 |     if (dist == ans){
      |     ~~~~~~~~~~~~~~~~~   
   92 |         if (abs(x-y) == (m-abs(x-y))){
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   93 |             cnt += max(colichestvo[cycle[x]],1ll)*max(1ll,colichestvo[cycle[y]])*2;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   94 |         }
      |         ~               
   95 |         else
      |         ~~~~            
   96 |             cnt += colichestvo[cycle[x]]*colichestvo[cycle[y]];
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   97 |     }
      |     ~                   
   98 | }
      | ~                       
   99 | 
      |                         
  100 | 
      |                         
  101 | main(){
      | ~~~~~~~                 
  102 | 
      |                         
  103 |     int n,i,j;
      |     ~~~~~~~~~~          
  104 |     scan1(n)
      |     ~~~~~~~             
shymbulak.cpp:104:5: note: in expansion of macro 'scan1'
  104 |     scan1(n)
      |     ^~~~~
shymbulak.cpp:14:26: note: format string is defined here
   14 | #define scan1(a) scanf("%d",&a);
      |                         ~^
      |                          |
      |                          int*
      |                         %lld
shymbulak.cpp:15:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                          ^~~~~~~ ~~~~~~~~
      |                                  |
      |                                  long long int*
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~      
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~    
   22 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~         
   23 | const int N = 1e6+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24 | 
      |                           
   25 | vector <int> g[N],cycle,v;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | pii ver[N];
      | ~~~~~~~~~~~               
   27 | bool bosh[N],vis[N];
      | ~~~~~~~~~~~~~~~~~~~~      
   28 | void dfs_cycle(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     vis[x] = 1;
      |     ~~~~~~~~~~~           
   30 |     int i,j;
      |     ~~~~~~~~              
   31 |     v.pb(x);
      |     ~~~~~~~~              
   32 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   33 |         int to = g[x][i];
      |         ~~~~~~~~~~~~~~~~~ 
   34 |         if (vis[to] == 1 && to != p){
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   35 |             bool f=0;
      |             ~~~~~~~~~     
   36 |             for (j=0;j<v.size();++j){
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                 if (v[j] == to)f=1;
      |                 ~~~~~~~~~~~~~~~~~~~
   38 |                 if (f){
      |                 ~~~~~~~   
   39 |                     cycle.pb(v[j]);
      |                     ~~~~~~~~~~~~~~~
   40 |                 }
      |                 ~         
   41 | 
      |                           
   42 |             }
      |             ~             
   43 |         }
      |         ~                 
   44 |         if (vis[to] == 0){
      |         ~~~~~~~~~~~~~~~~~~
   45 |             dfs_cycle(to,x);
      |             ~~~~~~~~~~~~~~~~
   46 |         }
      |         ~                 
   47 |     }
      |     ~                     
   48 |     v.pop_back();
      |     ~~~~~~~~~~~~~         
   49 | }
      | ~                         
   50 | 
      |                           
   51 | int dlina[N],colichestvo[N];
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   52 | 
      |                           
   53 | void dfs_diametr(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   54 |     int i;
      |     ~~~~~~                
   55 |     if (g[x].size() == 1){
      |     ~~~~~~~~~~~~~~~~~~~~~~
   56 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   57 |         ret;
      |         ~~~~              
   58 |     }
      |     ~                     
   59 |     vector <pii> tmp;
      |     ~~~~~~~~~~~~~~~~~     
   60 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   61 |         if (g[x][i] == p || bosh[g[x][i]])continue;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   62 |         dfs_diametr(g[x][i],x);
      |         ~~~~~~~~~~~~~~~~~~~~~~~
   63 |         tmp.pb({dlina[g[x][i]],colichestvo[g[x][i]]});
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   64 |     }
      |     ~                     
   65 |     if (tmp.size() == 0){
      |     ~~~~~~~~~~~~~~~~~~~~~ 
   66 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   67 |         ret;
      |         ~~~~              
   68 |     }
      |     ~                     
   69 |     sort(allr(tmp));
      |     ~~~~~~~~~~~~~~~~      
   70 |     int mx = tmp[0].fr,cnt = tmp[0].sc;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71 |     for (i=1;i<tmp.size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 | 
      |                           
   73 |         if (tmp[i].fr == mx){
      |         ~~~~~~~~~~~~~~~~~~~~~
   74 |             cnt += tmp[i].sc;
      |             ~~~~~~~~~~~~~~~~~
   75 |         }
      |         ~                 
   76 | 
      |                           
   77 |     }
      |     ~                     
   78 |     dlina[x] = mx+1;
      |     ~~~~~~~~~~~~~~~~      
   79 |     colichestvo[x] = cnt;
      |     ~~~~~~~~~~~~~~~~~~~~~ 
   80 | }
      | ~                         
   81 | int ans,cnt;
      | ~~~~~~~~~~~~              
   82 | 
      |                           
   83 | int calc(int x,int y,int m){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   84 |     int dist = min(abs(x-y),m-abs(x-y));
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   85 |     dist += dlina[cycle[x]];
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   86 |     dist += dlina[cycle[y]];
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
   87 |     if (ans < dist){
      |     ~~~~~~~~~~~~~~~~      
   88 |         ans = dist;
      |         ~~~~~~~~~~~       
   89 |         cnt=0;
      |         ~~~~~~            
   90 |     }
      |     ~                     
   91 |     if (dist == ans){
      |     ~~~~~~~~~~~~~~~~~     
   92 |         if (abs(x-y) == (m-abs(x-y))){
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   93 |             cnt += max(colichestvo[cycle[x]],1ll)*max(1ll,colichestvo[cycle[y]])*2;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   94 |         }
      |         ~                 
   95 |         else
      |         ~~~~              
   96 |             cnt += colichestvo[cycle[x]]*colichestvo[cycle[y]];
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   97 |     }
      |     ~                     
   98 | }
      | ~                         
   99 | 
      |                           
  100 | 
      |                           
  101 | main(){
      | ~~~~~~~                   
  102 | 
      |                           
  103 |     int n,i,j;
      |     ~~~~~~~~~~            
  104 |     scan1(n)
      |     ~~~~~~~~              
  105 |     for (i=1;i<=n;++i){
      |     ~~~~~~~~~~~~~~~~~~~   
  106 |         int x,y;
      |         ~~~~~~~~          
  107 |         scan2(x,y)
      |         ~~~~~~~           
shymbulak.cpp:107:9: note: in expansion of macro 'scan2'
  107 |         scan2(x,y)
      |         ^~~~~
shymbulak.cpp:15:28: note: format string is defined here
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                           ~^
      |                            |
      |                            int*
      |                           %lld
shymbulak.cpp:15:26: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                          ^~~~~~~     ~~~~
      |                                      |
      |                                      long long int*
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~      
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~    
   22 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~         
   23 | const int N = 1e6+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24 | 
      |                           
   25 | vector <int> g[N],cycle,v;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | pii ver[N];
      | ~~~~~~~~~~~               
   27 | bool bosh[N],vis[N];
      | ~~~~~~~~~~~~~~~~~~~~      
   28 | void dfs_cycle(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     vis[x] = 1;
      |     ~~~~~~~~~~~           
   30 |     int i,j;
      |     ~~~~~~~~              
   31 |     v.pb(x);
      |     ~~~~~~~~              
   32 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   33 |         int to = g[x][i];
      |         ~~~~~~~~~~~~~~~~~ 
   34 |         if (vis[to] == 1 && to != p){
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   35 |             bool f=0;
      |             ~~~~~~~~~     
   36 |             for (j=0;j<v.size();++j){
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                 if (v[j] == to)f=1;
      |                 ~~~~~~~~~~~~~~~~~~~
   38 |                 if (f){
      |                 ~~~~~~~   
   39 |                     cycle.pb(v[j]);
      |                     ~~~~~~~~~~~~~~~
   40 |                 }
      |                 ~         
   41 | 
      |                           
   42 |             }
      |             ~             
   43 |         }
      |         ~                 
   44 |         if (vis[to] == 0){
      |         ~~~~~~~~~~~~~~~~~~
   45 |             dfs_cycle(to,x);
      |             ~~~~~~~~~~~~~~~~
   46 |         }
      |         ~                 
   47 |     }
      |     ~                     
   48 |     v.pop_back();
      |     ~~~~~~~~~~~~~         
   49 | }
      | ~                         
   50 | 
      |                           
   51 | int dlina[N],colichestvo[N];
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   52 | 
      |                           
   53 | void dfs_diametr(int x,int p){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   54 |     int i;
      |     ~~~~~~                
   55 |     if (g[x].size() == 1){
      |     ~~~~~~~~~~~~~~~~~~~~~~
   56 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   57 |         ret;
      |         ~~~~              
   58 |     }
      |     ~                     
   59 |     vector <pii> tmp;
      |     ~~~~~~~~~~~~~~~~~     
   60 |     for (i=0;i<g[x].size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   61 |         if (g[x][i] == p || bosh[g[x][i]])continue;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   62 |         dfs_diametr(g[x][i],x);
      |         ~~~~~~~~~~~~~~~~~~~~~~~
   63 |         tmp.pb({dlina[g[x][i]],colichestvo[g[x][i]]});
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   64 |     }
      |     ~                     
   65 |     if (tmp.size() == 0){
      |     ~~~~~~~~~~~~~~~~~~~~~ 
   66 |         colichestvo[x] = 1;
      |         ~~~~~~~~~~~~~~~~~~~
   67 |         ret;
      |         ~~~~              
   68 |     }
      |     ~                     
   69 |     sort(allr(tmp));
      |     ~~~~~~~~~~~~~~~~      
   70 |     int mx = tmp[0].fr,cnt = tmp[0].sc;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71 |     for (i=1;i<tmp.size();++i){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 | 
      |                           
   73 |         if (tmp[i].fr == mx){
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 47980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 47 ms 47980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 47980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -