답안 #1064753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064753 2024-08-18T17:26:03 Z XJP12 기지국 (IOI20_stations) C++14
0 / 100
2 ms 600 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vvi g;
vi vis;
vi l;
vi indeg;
int y=-1;
int cont=0;
void dfs1(int u, int p){
    // cout<<u<< " ";
    vis[u]=true;
    if(u==y){
        l[u]=1000+l[p];
    }else{
        l[u]=cont;
        cont++;
    }
   for(auto v: g[u]){
        if(!vis[v]){
            dfs1(v,u);
        }
    }
}
void dfs(int u){

    vis[u]=true;
    l[u]=cont;
    cont++;
    for(auto v: g[u]){
        if(!vis[v]){
            dfs(v);
        }
    }
}
vi label(int n, int k, vi u, vi v) {
    l.resize(n,0);
    vis.resize(n,0);
    indeg.resize(n,0);
    g.resize(n, vi());
    y=-1;
    cont=0;
    for(int i=0; i<n-1; i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
        indeg[u[i]]++;
        indeg[v[i]]++;
    }
    vi x;
    for(int i=n-1; i>=0; i--){
        if(indeg[i]==1) x.push_back(i);
        if(indeg[i]==3) y=i;
      //  cout<<x<<y<<endl;
    }
    if(k>1000 && y!=-1){
        int a=g[y][0],  b = g[y][1],  c=g[y][2];
        int x1=-1;
        for(int i=0; i<x.size(); i++){
            if(x[i]!=a && x[i]!=b && x[i]!=c){
                 x1=x[i];
            }else{
                if(x[i]==a) y=a;
                if(x[i]==b) y=b;
                if(x[i]==c) y=c;
            }
        }
      //  cout<<y<<endl;
        if(x1==-1){
            if(y!=a){
                x1=a;
            }else{
                x1=b;
            }
        }
        dfs1(x1,x1);
    }else{
        dfs(x[0]);
    }

	return l;
}
int find_next_station(int s, int t, vi c) {
   return c[0];
}

Compilation message

stations.cpp: In function 'vi label(int, int, vi, vi)':
stations.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int i=0; i<x.size(); i++){
      |                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -