답안 #340653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340653 2020-12-28T05:03:31 Z beksultan04 관광지 (IZhO14_shymbulak) C++14
0 / 100
87 ms 26860 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],coun;
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 dis_dfs(int x,int p,int cnt){
    int i,mx = 0;
    dis[pos] = max(dis[pos],cnt);
    for (i=0;i<g[x].size();++i){
        int to = g[x][i];
        if (bas[to] || to == p)continue;
        dis_dfs(to,x,cnt+1);
    }
}
int maax;
void ans_dfs(int x,int p,int cnt){
    int i = 0;
    if (cnt == maax) coun++;
    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);
    }
}

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];
        dis_dfs(cycle[i],0,0);
        maax = max(maax,dis[pos]);
    }
    for (i=0;i<cycle.size();++i){
        ans_dfs(cycle[i],0,0);
    }
    cout <<coun*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 dis_dfs(int, int, int)':
shymbulak.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp:52:11: warning: unused variable 'mx' [-Wunused-variable]
   52 |     int i,mx = 0;
      |           ^~
shymbulak.cpp: In function 'void ans_dfs(int, int, int)':
shymbulak.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
shymbulak.cpp: At global scope:
shymbulak.cpp:71:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main(){
      |      ^
shymbulak.cpp: In function 'int main()':
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:84:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:89:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for (i=0;i<cycle.size();++i){
      |              ~^~~~~~~~~~~~~
shymbulak.cpp:72:11: warning: unused variable 'm' [-Wunused-variable]
   72 |     int n,m,i,j;
      |           ^
shymbulak.cpp:72:15: warning: unused variable 'j' [-Wunused-variable]
   72 |     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:73:5: note: in expansion of macro 'scan1'
   73 |     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:76:9: note: in expansion of macro 'scan2'
   76 |         scan2(x,y)
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 26860 KB Output isn't correct
2 Halted 0 ms 0 KB -