제출 #377760

#제출 시각아이디문제언어결과실행 시간메모리
377760AlexRex0Traffic (IOI10_traffic)C++14
컴파일 에러
0 ms0 KiB
#include <stdio.h> #include <bits/stdc++.h> using namespace std; vector<int> g[1000002]; long long int sub[1000002]; bool visitado[1000002]; bool visitado2[1000002]; int v[1000002]; long long int dfs(int nodo, int padre){ sub[nodo]+= v[nodo]; for(int i = 0 ; i < g[nodo].size(); ++i){ if(g[nodo][i] != padre){ sub[nodo]+= dfs(g[nodo][i], nodo); } } return sub[nodo]; } long long int indRes, indMax = -1, Max, aux, Res, ayuda; static int N,P[1000000],S[1000000],D[1000000]; int LocateCentre(int N, int pp[], int S[], int D[]) { for(int i = 0; i < N - 1; ++i){ g[S[i]].push_back(D[i]); g[D[i]].push_back(S[i]); v[i] = pp[i]; } v[N - 1] = pp[N - 1]; dfs(0, -1); Max = -1; for(int i = 0; i < g[0].size(); ++i){ ayuda = sub[g[0][i]]; if(ayuda > Max){ Max = ayuda; } } Res = Max; visitado2[0] = true; while(true){ Max = -1; for(int i = 0; i < g[aux].size(); ++i){ ayuda = sub[g[aux][i]]; if(ayuda > Max){ Max = ayuda; indMax = g[aux][i]; } } if(visitado2[indMax]){ if(Max < Res){ indRes = aux; Res = Max; } return indRes; } visitado2[indMax] = true; if(Max < Res){ indRes = aux; Res = Max; } sub[aux]-= sub[indMax]; sub[indMax]+= sub[aux]; if(indRes == indMax){ break; } aux = indMax; } return indRes; } int main(){ int i; scanf("%d",&N); for (i=0;i<N;i++) scanf("%d",&P[i]); for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]); int r = LocateCentre(N,P,S,D); printf("%d\n",r); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

traffic.cpp: In function 'long long int dfs(int, int)':
traffic.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i = 0 ; i < g[nodo].size(); ++i){
      |                     ~~^~~~~~~~~~~~~~~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < g[0].size(); ++i){
      |                    ~~^~~~~~~~~~~~~
traffic.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i = 0; i < g[aux].size(); ++i){
      |                        ~~^~~~~~~~~~~~~~~
traffic.cpp: In function 'int main()':
traffic.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |    scanf("%d",&N);
      |    ~~~~~^~~~~~~~~
traffic.cpp:71:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |    for (i=0;i<N;i++) scanf("%d",&P[i]);
      |                      ~~~~~^~~~~~~~~~~~
traffic.cpp:72:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |    for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~
/tmp/ccFob3El.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccOCnJGn.o:traffic.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status