제출 #709930

#제출 시각아이디문제언어결과실행 시간메모리
709930raysh07기지국 (IOI20_stations)C++17
0 / 100
3022 ms2097152 KiB
//#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define INF (int)1e9
const int N = 1005;
int timer = 0;
int tin[N], tout[N];
vector <int> adj[N];
int ans[N];

void dfs(int u, int par = -1, int dist = 0){
    tin[u] = ++timer;
    
    for (int v: adj[u]){
        if (v != par){
            dfs(v, u, dist + 1);
        }
    }
    
    tout[u] = ++timer;
    
    if (dist & 1) ans[u] = tout[u]; 
    else ans[u] = tin[u];
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for (int i=0; i<n-1; i++){
	    adj[u[i]].push_back(v[i]);
	    adj[v[i]].push_back(u[i]);
	}
	
	dfs(0);
	
	int ptr = -1;
	set <int> st; map <int, int> comp;
	for (int i=0; i<n; i++) st.insert(ans[i]);
	for (auto x: st) comp[x] = ++ptr;
	
	assert(st.size() == n);
	
	vector <int> lab;
	for (int i=0; i<n; i++) lab.push_back(comp[ans[i]]);
	return lab;
}

int find_next_station(int s, int t, vector<int> c) {
    return c[0];
	if (s==0){
	    //root 
	    for (auto x: c){
	        if (x >= t) return x;
	    }
	    assert(false);
	}
	
	if (c.size() == 1) return c[0];
	//either s is tin time of u, in which case, rest all are tout times 
	//tout of everything else shud be strictly larger 
	
	//else s is tout time of u, in which case rest all are tin times 
	//tin of everything else shud be strictly smaller 
	
	if (s > c[0]){
	    //this is tout time
	    //rest all are tin time 
	    
	    //if t is not in range [c[1], s] its not in subtree 
	    if (t < c[1] || t > s) return c[0];
	    c.push_back(INF);
	    for (int i=2; i<c.size(); i++){
	        if (c[i] > t) return c[i-1];
	    }
	}
	else {
	    assert(s < c[0]);
	    
	    //now range is [s, c[c.size() - 2]
	    if (t < s || t > c[c.size() - 2]) return c.back();
	    
	    for (int i=0; i<c.size() - 1; i++){
	        if (t <= c[i]) return c[i];
	    }
	}
}

컴파일 시 표준 에러 (stderr) 메시지

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from stations.cpp:2:
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:39:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |  assert(st.size() == n);
      |         ~~~~~~~~~~^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |      for (int i=2; i<c.size(); i++){
      |                    ~^~~~~~~~~
stations.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |      for (int i=0; i<c.size() - 1; i++){
      |                    ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...