답안 #305579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305579 2020-09-23T15:24:36 Z kishtarn555 기지국 (IOI20_stations) C++14
0 / 100
2 ms 384 KB
#include "stations.h"
#include <vector>
#include <algorithm>
#include <iostream>
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);
    for (int i=0; i< n; i++) {
        cout << i<<":"<<labels[i]<<"!"<<endl;
    }
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    sort(c.begin(), c.end());
    cout << "("<<s<<","<<t<<")";
    for (int i =0; i< c.size(); i++) {
        cout << " "<<c[i];
    }
    cout << "!"<<endl;
    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 (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 >=0; i--){
            if (c[i] <= t && t <= prev) return c[i];
            prev=c[i];
        }
        return -2;
    } else {
        if(t<s||t>c[c.size()-1]) return c[c.size()-1];
        int prev=s;
        for (int i = 0; i < c.size(); i++) {
            if (prev<= t && t <= c[i])return c[i];
            prev=c[i];
        }
        return -3;

    }

}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for (int i =0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:21: 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:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i =0; i < c.size(); i++) {
      |                    ~~^~~~~~~~~~
stations.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int i=0; i < c.size(); i++) {
      |                       ~~^~~~~~~~~~
stations.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int i = 0; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Expected integer, but "0:0!" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Expected integer, but "0:0!" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Expected integer, but "0:0!" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Expected integer, but "0:0!" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "0:0!" found
2 Halted 0 ms 0 KB -