답안 #433090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433090 2021-06-18T20:35:01 Z Enkognit 기지국 (IOI20_stations) C++14
0 / 100
5 ms 920 KB
#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

vector<ll> c[1005];
ll T;
ll in[1005], out[1005], pp[1005];

void dfs(int h,int p=-1)
{
    pp[h]=p;

    in[h]=++T;

    for (int i = 0; i < c[h].size(); i++)
        if (c[h][i]!=p)
        {
            dfs(c[h][i], h);
        }

    out[h]=++T;
}

bool is_ancestor(int x,int y)
{
    return in[x]<=in[y] && out[x]>=out[y];
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	T=0;
	for (int i = 0; i < n; i++) {
		labels[i] = i;
		c[i].clear();
	}

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

    dfs(0);

	return labels;
}

ll TT;

bool dfs2(int h,int p=-1)
{
    if (h==TT) return 1;
    for (int i = 0; i < c[h].size(); i++)
        if (c[h][i]!=p)
        {
            if (dfs2(c[h][i], h)) return 1;
        }
    return 0;
}

int find_next_station(int s, int t, std::vector<int> cc)
{
    //cout << "!\n";
    if (!is_ancestor(s, t))
    {
        TT=t;
        assert(dfs2(pp[s], s));
        return pp[s];
    }
    for (int i = 0; i < cc.size(); i++)
        if (is_ancestor(cc[i], t) && pp[s]!=cc[i])
        {
            TT=t;
            assert(dfs2(cc[i], s));
            return cc[i];
        }
}
/*
1
5 10
0 1
1 2
1 3
2 4
2
2 0 2
1 3 3
*/

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < c[h].size(); i++)
      |                     ~~^~~~~~~~~~~~~
stations.cpp: In function 'bool dfs2(int, int)':
stations.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < c[h].size(); i++)
      |                     ~~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 0; i < cc.size(); i++)
      |                     ~~^~~~~~~~~~~
stations.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
   84 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 912 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 780 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 904 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 760 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 920 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -