Submission #1205318

#TimeUsernameProblemLanguageResultExecution timeMemory
1205318notme기지국 (IOI20_stations)C++20
5 / 100
306 ms600 KiB
#include "stations.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn = 2e3 + 10;
vector < int > g[maxn];

int degree[maxn];
int depth[maxn], used[maxn];
void dfs(int beg, int from, int h)
{
    used[beg]= 1;
    depth[beg] = h;
    for (auto nb: g[beg])
    {

        if(used[nb])
        {
            assert(nb == from);
            continue;
        }
        dfs(nb, beg, h+1);
    }
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v)
{
    memset(degree, 0, sizeof(degree));
    memset(used, 0, sizeof(used));
    memset(depth, 0, sizeof(depth));
    for (int i = 0; i <= n; ++ i)
        g[i].clear();
    assert(u.size() == n-1);
    for (int i = 0; i < n-1; ++ i)
    {
        assert(u[i] != v[i]);
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
        degree[u[i]] ++;
        degree[v[i]] ++;
    }
    int root = -1;
    int sum = 0;
    for (int i = 0; i < n; ++ i)
    {
      sum += degree[i];
        if(degree[i] == 1)
        {
            root = i;
            break;
        }
    }
   // assert(sum == (n-1) * 2);
    std::vector<int> labels(n);

    if(root == -1)
    {
        for (int i = 0; i < n; ++ i)
        {
            labels[i] = i;
        }
        return labels;
    }
    dfs(root, -1, 0);

    for (int i = 0; i < n; i++)
    {
        labels[i] = depth[i];
    }
    return labels;
}

int find_next_station(int s, int t, std::vector<int> c)
{
  // if(c.size() == 2)return c[0];
    if(t > s)
    {
        for (auto x: c)
        {
            if(x > s)return x;
        }
    }
    else
    {
        for (auto x: c)
        {
            if(x < s)return x;
        }
    }
}
/**
2
7 10000000
0 1
0 2
0 6
2 3
2 4
3 5
4
6 3 0
4 1 2
3 4 2
4 3 2
7 10000000
0 1
0 2
0 6
2 3
2 4
3 5
4
6 3 0
1 3 0
3 4 2
4 3 2
*/

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^
#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...