답안 #306863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306863 2020-09-26T11:43:54 Z Ruxandra985 기지국 (IOI20_stations) C++14
5 / 100
933 ms 1280 KB
#include <bits/stdc++.h>
#include "stations.h"
#define DIMN 1010

using namespace std;
int poz;
int lab[DIMN] , last[DIMN] , niv[DIMN];
vector <int> ww[DIMN];
void dfs (int nod , int tt , int lvl){
    int i , vecin;

    //printf ("%d ", nod);

    if (lvl % 2 == 0)
        poz++;

    lab[nod] = poz;

    niv[nod] = lvl;

    for (i = 0 ; i < ww[nod].size() ; i++){
        vecin = ww[nod][i];
        if (vecin != tt){
            dfs (vecin , nod , lvl + 1);

        }
    }

    if (lvl % 2 == 1)
        poz++;

    last[nod] = poz;


}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels;

	labels.resize(n);

	for (int i = 0 ; i < n ; i++)
        ww[i].clear();

	for (int i = 0; i <= n - 2; i++) {
		ww[u[i]].push_back(v[i]);
		ww[v[i]].push_back(u[i]);
	}
	poz = 0;
	dfs (0 , -1 , 0);

	for (int i = 0 ; i < n ; i++){
        if (niv[i] % 2 == 0)
            labels[i] = lab[i];
        else labels[i] = last[i];
	}

	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	int i;

	//if (s == 29 && t == 8)
      //  printf ("%d\n\n\n",c[0]);

	if (c.size() == 1)
        return c[0];

	if (s == 1){ /// incep din 0, e nivel par oricum

        for (i = 0 ; i <= c.size() - 1 ; i++){

            if (c[i] < t && t <= c[i + 1])
                return c[i + 1];

        }

        return c[0];

	}
	else { /// unul dintre vecini e clar tatal

        if (s < c[0]){ /// s e un nivel par
            if (s <= t && t <= c[0])
                return c[0];
            for (i = 0 ; i <= c.size() - 2 ; i++){

                if (c[i] < t && t <= c[i + 1])
                    return c[i + 1];

            }

            return c.back();
        }
        else { /// s e un nivel impar
            for (i = 1 ; i <= c.size() - 1 ; i++){

                if (c[i] <= t && t < c[i + 1])
                    return c[i];

            }

            if (t >= c.back() && t < s)
                return c.back();
            return c[0];
        }

	}

}

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (i = 0 ; i < ww[nod].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (i = 0 ; i <= c.size() - 1 ; i++){
      |                      ~~^~~~~~~~~~~~~~~
stations.cpp:87:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for (i = 0 ; i <= c.size() - 2 ; i++){
      |                          ~~^~~~~~~~~~~~~~~
stations.cpp:97:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             for (i = 1 ; i <= c.size() - 1 ; i++){
      |                          ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 531 ms 1024 KB Output is correct
2 Correct 463 ms 1008 KB Output is correct
3 Correct 875 ms 868 KB Output is correct
4 Correct 661 ms 860 KB Output is correct
5 Correct 588 ms 864 KB Output is correct
6 Correct 455 ms 1024 KB Output is correct
7 Correct 477 ms 1024 KB Output is correct
8 Correct 3 ms 876 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 436 ms 1024 KB Output is correct
2 Incorrect 551 ms 800 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 570 ms 1024 KB Output is correct
2 Correct 448 ms 1024 KB Output is correct
3 Correct 843 ms 1040 KB Output is correct
4 Correct 650 ms 768 KB Output is correct
5 Correct 587 ms 768 KB Output is correct
6 Correct 447 ms 1008 KB Output is correct
7 Correct 441 ms 1024 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 4 ms 868 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 580 ms 864 KB Output is correct
12 Incorrect 458 ms 1024 KB Wrong query response.
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 901 ms 860 KB Output is correct
2 Correct 659 ms 868 KB Output is correct
3 Correct 565 ms 780 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 2 ms 868 KB Output is correct
7 Correct 608 ms 864 KB Output is correct
8 Correct 867 ms 768 KB Output is correct
9 Correct 675 ms 768 KB Output is correct
10 Correct 599 ms 1040 KB Output is correct
11 Incorrect 5 ms 868 KB Wrong query response.
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 1024 KB Output is correct
2 Correct 464 ms 1024 KB Output is correct
3 Correct 933 ms 1008 KB Output is correct
4 Correct 661 ms 1040 KB Output is correct
5 Correct 578 ms 996 KB Output is correct
6 Correct 554 ms 1280 KB Output is correct
7 Correct 549 ms 768 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 513 ms 932 KB Output is correct
12 Incorrect 537 ms 808 KB Wrong query response.
13 Halted 0 ms 0 KB -