답안 #377735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377735 2021-03-14T21:34:14 Z AlexRex0 Traffic (IOI10_traffic) C++14
0 / 100
20 ms 23788 KB
#include "traffic.h"
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000002];
long long int sub[1000002];
bool visitado[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;
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);
    while(true){
        Max = -1;
        for(int i = 0; i < g[aux].size(); ++i){
            if(sub[g[aux][i]] > Max){
                Max = sub[g[aux][i]];
                indMax = g[aux][i];
            }
        }
        sub[aux]-= sub[indMax];
        sub[indMax]+= sub[aux];
        if(indRes == indMax){
            break;
        }
        indRes = aux;
        aux = indMax;
    }
    return aux;
}

Compilation message

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:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i = 0; i < g[aux].size(); ++i){
      |                        ~~^~~~~~~~~~~~~~~
traffic.cpp: At global scope:
traffic.cpp:19:36: warning: 'D' defined but not used [-Wunused-variable]
   19 | static int N,P[1000000],S[1000000],D[1000000];
      |                                    ^
traffic.cpp:19:25: warning: 'S' defined but not used [-Wunused-variable]
   19 | static int N,P[1000000],S[1000000],D[1000000];
      |                         ^
traffic.cpp:19:14: warning: 'P' defined but not used [-Wunused-variable]
   19 | static int N,P[1000000],S[1000000],D[1000000];
      |              ^
traffic.cpp:19:12: warning: 'N' defined but not used [-Wunused-variable]
   19 | static int N,P[1000000],S[1000000],D[1000000];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Incorrect 17 ms 23788 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Incorrect 17 ms 23788 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Incorrect 17 ms 23788 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Incorrect 17 ms 23788 KB Output isn't correct
5 Halted 0 ms 0 KB -