답안 #290252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290252 2020-09-03T14:44:23 Z SamAnd Simurgh (IOI17_simurgh) C++17
51 / 100
262 ms 2680 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;
            break;
        }
        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 (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;
            }
        }
        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 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 3 ms 512 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 3 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 3 ms 512 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 3 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
34 Correct 253 ms 1408 KB correct
35 Correct 252 ms 1656 KB correct
36 Correct 170 ms 1384 KB correct
37 Correct 11 ms 896 KB correct
38 Correct 262 ms 1640 KB correct
39 Correct 215 ms 1528 KB correct
40 Correct 169 ms 1280 KB correct
41 Correct 254 ms 1656 KB correct
42 Correct 254 ms 1656 KB correct
43 Correct 132 ms 1280 KB correct
44 Correct 108 ms 1152 KB correct
45 Correct 129 ms 1152 KB correct
46 Correct 99 ms 1152 KB correct
47 Correct 45 ms 896 KB correct
48 Correct 4 ms 768 KB correct
49 Correct 12 ms 896 KB correct
50 Correct 43 ms 896 KB correct
51 Correct 125 ms 1152 KB correct
52 Correct 105 ms 1152 KB correct
53 Correct 96 ms 1152 KB correct
54 Correct 136 ms 1280 KB correct
55 Correct 134 ms 1268 KB correct
56 Correct 127 ms 1152 KB correct
57 Correct 129 ms 1264 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 198 ms 2680 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 3 ms 512 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 3 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
34 Correct 253 ms 1408 KB correct
35 Correct 252 ms 1656 KB correct
36 Correct 170 ms 1384 KB correct
37 Correct 11 ms 896 KB correct
38 Correct 262 ms 1640 KB correct
39 Correct 215 ms 1528 KB correct
40 Correct 169 ms 1280 KB correct
41 Correct 254 ms 1656 KB correct
42 Correct 254 ms 1656 KB correct
43 Correct 132 ms 1280 KB correct
44 Correct 108 ms 1152 KB correct
45 Correct 129 ms 1152 KB correct
46 Correct 99 ms 1152 KB correct
47 Correct 45 ms 896 KB correct
48 Correct 4 ms 768 KB correct
49 Correct 12 ms 896 KB correct
50 Correct 43 ms 896 KB correct
51 Correct 125 ms 1152 KB correct
52 Correct 105 ms 1152 KB correct
53 Correct 96 ms 1152 KB correct
54 Correct 136 ms 1280 KB correct
55 Correct 134 ms 1268 KB correct
56 Correct 127 ms 1152 KB correct
57 Correct 129 ms 1264 KB correct
58 Correct 1 ms 384 KB correct
59 Correct 1 ms 384 KB correct
60 Incorrect 198 ms 2680 KB WA in grader: NO
61 Halted 0 ms 0 KB -