답안 #290242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290242 2020-09-03T14:38:25 Z SamAnd Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 384 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 503;

int n, m;
int g[N][N];

vector<pair<int, int> > t[N];

bool c[N];
vector<int> r;
void dfs0(int x)
{
    c[x] = true;
    for (int h = 0; h < n; ++h)
    {
        if (!g[x][h])
            continue;
        if (c[h])
            continue;
        t[x].push_back(m_p(h, g[x][h] - 1));
        t[h].push_back(m_p(x, g[x][h] - 1));
        r.push_back(g[x][h] - 1);
        dfs0(h);
    }
}

vector<int> v;
bool dfs(int x, int p, int y)
{
    if (x == y)
        return true;
    for (int i = 0; i < t[x].size(); ++i)
    {
        int h = t[x][i].fi;
        if (h == p)
            continue;
        v.push_back(t[x][i].se);
        if (dfs(h, x, y))
            return true;
        v.pop_back();
    }
    return false;
}

void bilt(const vector<int>& u_, const vector<int>& v_)
{
    for (int x = 0; x < n; ++x)
    {
        t[x].clear();
    }
    for (int i = 0; i < n - 1; ++i)
    {
        int x = u_[r[i]];
        int y = v_[r[i]];
        t[x].push_back(m_p(y, r[i]));
        t[y].push_back(m_p(x, r[i]));
    }
}

int u[N * N];

std::vector<int> find_roads(int n_, std::vector<int> u_, std::vector<int> v_)
{
    n = n_;
    m = sz(u_);
    for (int i = 0; i < m; ++i)
    {
        int x = u_[i];
        int y = v_[i];
        g[x][y] = i + 1;
        g[y][x] = i + 1;
    }

    dfs0(0);
    int ans = count_common_roads(r);
    if (ans == n - 1)
        return r;

    for (int i = 0; i < m; ++i)
    {
        int x = u_[i];
        int y = v_[i];
        v.clear();
        dfs(x, x, y);
        if (sz(v) == 1)
            continue;
        for (int j = 0; j < sz(v); ++j)
        {
            if (!u[v[j]])
                continue;
            vector<int> yr;
            for (int i = 0; i < n - 1; ++i)
            {
                if (r[i] == v[j])
                    continue;
                yr.push_back(r[i]);
            }
            yr.push_back(i);
            int yans = count_common_roads(yr);
            if (yans == ans)
                u[i] = u[v[j]];
            else if (yans < ans)
                u[i] = -1;
            else
                u[i] = 1;
        }
        if (u[i])
            continue;
        for (int j = 0; j < sz(v); ++j)
        {
            vector<int> yr;
            for (int i = 0; i < n - 1; ++i)
            {
                if (r[i] == v[j])
                    continue;
                yr.push_back(r[i]);
            }
            yr.push_back(i);
            int yans = count_common_roads(yr);

            if (u[i])
            {
                if (yans == ans)
                    u[v[j]] = u[i];
                else if (yans < ans)
                    u[v[j]] = 1;
                else
                    u[v[j]] = -1;
                continue;
            }

            if (ans == yans)
                continue;
            if (yans > ans)
            {
                /*r = yr;
                ans = yans;
                if (ans == n - 1)
                    return r;
                bilt(u_, v_);*/
                u[i] = 1;
                for (int jj = 0; jj < j; ++jj)
                    u[v[jj]] = 1;
                u[v[j]] = -1;
            }
            else
            {
                u[i] = -1;
                for (int jj = 0; jj < j; ++jj)
                    u[v[jj]] = -1;
                u[v[j]] = 1;
            }
            break;
        }
        if (!u[i])
        {
            u[i] = -1;
            for (int j = 0; j < sz(v); ++j)
                u[v[j]] = -1;
        }
    }
    r.clear();
    for (int i = 0; i < m; ++i)
    {
        if (u[i] >= 0)
            r.push_back(i);
    }
    return r;
}

Compilation message

simurgh.cpp: In function 'bool dfs(int, int, int)':
simurgh.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < t[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Incorrect 1 ms 384 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -