답안 #415615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415615 2021-06-01T09:43:41 Z MKopchev 기지국 (IOI20_stations) C++14
0 / 100
1022 ms 644 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e3+42;

vector<int> adj[nmax];

int in[nmax],out[nmax],when;

vector<int> outp;

void dfs(int node,int par,int depth)
{
    when++;

    in[node]=when;

    for(auto w:adj[node])
        if(w!=par)dfs(w,node,depth+1);

    when++;

    out[node]=when;

    if(depth%2==0)outp[node]=in[node];
    else outp[node]=out[node];
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	outp={};
	for(int i=0;i<n;i++)adj[i]={},outp.push_back(0);
	when=0;

	for(int i=0;i<n-1;i++)
    {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

	dfs(0,0,0);

	return outp;
}

int find_next_station(int s, int t, std::vector<int> c) {

	//cout<<"s= "<<s<<" t= "<<t<<" c= ";for(auto w:c)cout<<w<<" ";cout<<endl;

	for(auto w:c)
        if(w==t)return w;

    sort(c.begin(),c.end());

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

	if(s<c[0])
    {
        vector<int> c_in={s+1};
        vector<int> c_out=c;

        c_out.pop_back();

        for(int i=1;i<c_out.size();i++)
            c_in.push_back(c_out[i-1]+1);

        for(int i=0;i<c_in.size();i++)
            if(c_in[i]<=t&&t<=c_out[i])return c[i];

        return c.back();
    }
        vector<int> c_in=c;
        vector<int> c_out={};

        c_in.erase(c_in.begin(),c_in.begin()+1);

        for(int i=0;i+1<c_out.size();i++)
            c_out.push_back(c_in[i+1]-1);

        c_out.push_back(s-1);

        for(int i=0;i<c_in.size();i++)
            if(c_in[i]<=t&&t<=c_out[i])return c[i];

        return c.back();
}
/*
static int max_label = 0;
static int r, n, k, q;
static std::vector<int> u, v, labels, answers;
static std::map<int, int> reverse_labels;
static std::vector<std::vector<int>> adjlist;
static int s, t, w;
static std::vector<int> c;

int main() {
	assert(scanf("%d", &r) == 1);
	for (int tc = 0; tc < r; tc++) {
		assert(scanf("%d%d", &n, &k) == 2);
		u.resize(n - 1);
		v.resize(n - 1);
		adjlist.clear();
		adjlist.resize(n);
		for (int i = 0; i < n - 1; i++) {
			assert(scanf("%d%d", &u[i], &v[i]) == 2);
			adjlist[u[i]].push_back(v[i]);
			adjlist[v[i]].push_back(u[i]);
		}
		labels = label(n, k, u, v);
		if ((int)labels.size() != n) {
			printf("Number of labels not equal to %d\n", n);
			exit(0);
		}
		reverse_labels.clear();
		for (int i = 0; i < n; i++) {
			if (labels[i] < 0 || labels[i] > k) {
				printf("Label not in range 0 to %d\n", k);
				exit(0);
			}
			if (reverse_labels.find(labels[i]) != reverse_labels.end()) {
				printf("Labels not unique\n");
				exit(0);
			}
			reverse_labels[labels[i]] = i;
			if (labels[i] > max_label) {
				max_label = labels[i];
			}
		}
		assert(scanf("%d", &q) == 1);
		for (int i = 0; i < q; i++) {
			assert(scanf("%d%d%d", &s, &t, &w) == 3);
			c.clear();
			for (int v : adjlist[s]) {
				c.push_back(labels[v]);
			}
			std::sort(c.begin(), c.end());
			int answer = find_next_station(labels[s], labels[t], c);
			if (!std::binary_search(c.begin(), c.end(), answer)) {
				printf("Label %d returned by find_next_station not found in c\n", answer);
				exit(0);
			}
			answers.push_back(reverse_labels[answer]);
		}
	}
	printf("%d\n", max_label);
	for (int index : answers) {
		printf("%d\n", index);
	}
	exit(0);
}
*/

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int i=1;i<c_out.size();i++)
      |                     ~^~~~~~~~~~~~~
stations.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int i=0;i<c_in.size();i++)
      |                     ~^~~~~~~~~~~~
stations.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i=0;i+1<c_out.size();i++)
      |                     ~~~^~~~~~~~~~~~~
stations.cpp:81:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i=0;i<c_in.size();i++)
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 456 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1991
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 364 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1023
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 734 ms 644 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1022 ms 400 KB Output is correct
2 Correct 727 ms 496 KB Output is correct
3 Incorrect 653 ms 552 KB Wrong query response.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 613 ms 624 KB Wrong query response.
2 Halted 0 ms 0 KB -