Submission #340648

# Submission time Handle Problem Language Result Execution time Memory
340648 2020-12-28T04:45:24 Z beksultan04 Shymbulak (IZhO14_shymbulak) C++14
0 / 100
83 ms 28524 KB
#include <bits/stdc++.h>
using namespace std;
#define ll 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;
bool vis[N],bas[N];
int ans[N],pos,dis[N];
void dfs(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(to,x);
        }
    }
    v.pop_back();
}

void ans_dfs(int x,int p,int cnt){
    int i,mx = 0;
    for (i=0;i<g[x].size();++i){
        int to = g[x][i];
        if (bas[to] || to == p)continue;
        ans_dfs(to,x,cnt+1);
        dis[x] = dis[to]+1;
        mx = max(mx,dis[x]);
    }
    for (i=0;i<g[x].size();++i){
        int to = g[x][i];
        if (bas[to] || to == p)continue;
        if (dis[x] == mx && pos == x)ans[pos]++;

    }
}

main(){
    int n,m,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(1,0);
    for (i=0;i<cycle.size();++i){
        bas[cycle[i]]=1;
    }
    for (i=0;i<cycle.size();++i){
        pos=cycle[i];
        ans_dfs(cycle[i],0,0);
    }
    int mx = 0,cc=0;
    for (i=0;i<cycle.size();++i){
        mx = max(mx,dis[cycle[i]]);
    }

    for (i=0;i<cycle.size();++i){
        if (dis[cycle[i]] == mx)cc += ans[cycle[i]];
    }
    cout <<cc*2;

}




Compilation message

shymbulak.cpp: In function 'void dfs(int, int)':
shymbulak.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<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: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (j=0;j<v.size();++j){
      |                      ~^~~~~~~~~
shymbulak.cpp: In function 'void ans_dfs(int, int, int)':
shymbulak.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp: At global scope:
shymbulak.cpp:68:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      |      ^
shymbulak.cpp: In function 'int main()':
shymbulak.cpp:78:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:81:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:86:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:90:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:69:11: warning: unused variable 'm' [-Wunused-variable]
   69 |     int n,m,i,j;
      |           ^
shymbulak.cpp:69:15: warning: unused variable 'j' [-Wunused-variable]
   69 |     int n,m,i,j;
      |               ^
shymbulak.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
shymbulak.cpp:70:5: note: in expansion of macro 'scan1'
   70 |     scan1(n)
      |     ^~~~~
shymbulak.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
shymbulak.cpp:73:9: note: in expansion of macro 'scan2'
   73 |         scan2(x,y)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 28524 KB Output isn't correct
2 Halted 0 ms 0 KB -