답안 #305574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305574 2020-09-23T15:01:12 Z kishtarn555 기지국 (IOI20_stations) C++14
0 / 100
909 ms 1024 KB
#include "stations.h"
#include <vector>
#include <algorithm>
using namespace std;

void dfs(int cur, int ant, int & dtime, int h, vector<int> &labels, vector<vector<int> > & adj) {
    if (h%2==0)
        labels[cur]=dtime++;
    for (int ni: adj[cur]) {
        if (ni==ant)continue;
        dfs(ni, cur, dtime, h+1, labels, adj);
    }

    if (h%2==1) {
        labels[cur]=dtime++;
    }

}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		labels[i] = i;
	}
	int d =0;
	vector<vector<int> > adj(n);
	for (int i =0; i < u.size(); i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}
    dfs(0,0, d, 0, labels, adj);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    sort(c.begin(), c.end());
    for (int i =0; i < c.size(); i++) {
        if (c[i]==t)return t;
    }
    if (s==0) {
            int prev=0;
        for (int i=0; i < c.size(); i++) {
            if (i+1 == c.size())
                return c[i];
            if (prev <= t && t <= c[i])
                return c[i];
            prev=c[i];
        }
        return -1;
    }
    if (c[0] < s) {
        if (t < c[0] || t > s)return c[0];
        int prev=s;
        for (int i = c.size()-1; i >=1; i--){
            if (c[i] <= t && t <= prev) return c[i];
            prev=c[i];
        }
        return -1;
    } else {
        if(t<s||t>c[c.size()-1]) return c[c.size()-1];
        int prev=s;
        for (int i = 0; i < c.size()-1; i++) {
            if (s<= t && t <= c[i])return c[i];
            prev=c[i];
        }
        return -1;

    }

}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for (int i =0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i =0; i < c.size(); i++) {
      |                    ~~^~~~~~~~~~
stations.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i=0; i < c.size(); i++) {
      |                       ~~^~~~~~~~~~
stations.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if (i+1 == c.size())
      |                 ~~~~^~~~~~~~~~~
stations.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int i = 0; i < c.size()-1; i++) {
      |                         ~~^~~~~~~~~~~~
stations.cpp:60:13: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
   60 |         int prev=s;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 574 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 478 ms 832 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 550 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 909 ms 656 KB Output is correct
2 Incorrect 701 ms 660 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 683 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -