답안 #216496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216496 2020-03-27T11:38:00 Z emil_physmath Simurgh (IOI17_simurgh) C++17
30 / 100
372 ms 38648 KB
#include "simurgh.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define query count_common_roads
const int maxN = 500;
struct Jmp
{
    int to, ind;
    operator int&() { return to; }
    operator const int&() const { return to; }
};

int in[maxN], out[maxN];
Jmp par[maxN];
int gold[maxN * maxN];
vector<int> dfsq;
vector<Jmp> nei[maxN];
vector<int> same[maxN * maxN];
Jmp fup[maxN];

map<vector<int>, int> cache;
int Query(vector<int> q)
{
    auto it = cache.find(q);
    if (it != cache.end()) return it->second;
    return cache[q] = query(q);
}
inline bool Upper(int u, int v) { return in[u] <= in[v] && out[u] >= out[v]; }
bool used[maxN];
void DFS(int v, Jmp p)
{
    // cerr << "v: " << v << '\n';
    static int time = 0;
    used[v] = true;
    in[v] = ++time;
    par[v] = p;
    fup[v] = {-1, -1};
    for (Jmp to: nei[v])
        if (!used[to])
        {
            dfsq.push_back(to.ind);
            DFS(to, {v, to.ind});
            if (p != -1)
                if (fup[v] == -1 || (fup[to] != -1 && in[fup[to]] <= in[fup[v]]))
                    fup[v] = fup[to];
        }
        else if (to != p && p != -1)
            if (fup[v] == -1 || in[to] <= in[fup[v]])
                fup[v] = to;
    out[v] = time;
}

void DFS1(int v)
{
    for (int to: same[v])
        if (gold[to] == -1)
        {
            gold[to] = gold[v];
            DFS1(to);
        }
}
vector<int> find_roads(int n, vector<int> us, vector<int> vs)
{
    int m = us.size();
    fill(gold, gold + m, -1);
    for (int i = 0; i < m; ++i)
    {
        nei[us[i]].push_back({vs[i], i});
        nei[vs[i]].push_back({us[i], i});
    }
    DFS(0, {-1, -1});
    // for (int i = 0; i < n; ++i)
        // cerr << "fup[" << i << "] = " << fup[i].to << '\n';
    int dfsans = Query(dfsq);
    for (int i = 0; i < m; ++i)
        if (in[us[i]] > in[vs[i]])
            swap(us[i], vs[i]);
    for (int i = 0; i < m; ++i)
    {
        int u = us[i], v = vs[i];
        if (fup[v] == -1 || in[fup[v]] > in[u]) // Is a birdge.
        {
            gold[i] = 1;
            continue;
        }
        if (par[v] == u) continue;
        while (true)
        {
            int backe = i, dfse = par[v].ind;
            // cerr << dfse << ' ' << backe << '\n';
            int j = find(dfsq.begin(), dfsq.end(), dfse) - dfsq.begin();
            dfsq[j] = backe;
            int curans = Query(dfsq);
            if (curans == dfsans)
            {
                same[backe].push_back(dfse);
                same[dfse].push_back(backe);
            }
            else if (curans > dfsans)
                gold[backe] = 1, gold[dfse] = 0;
            else
                gold[backe] = 0, gold[dfse] = 1;
            dfsq[j] = dfse;
            if ((v = par[v]) == u) break;
        }
    }
    for (int i = 0; i < m; ++i)
        if (gold[i] != -1)
            DFS1(i);
    vector<int> ans;
    for (int i = 0; i < m; ++i)
        if (gold[i] == 1)
            ans.push_back(i);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6272 KB correct
2 Correct 8 ms 6272 KB correct
3 Correct 8 ms 6272 KB correct
4 Correct 8 ms 6272 KB correct
5 Correct 8 ms 6272 KB correct
6 Correct 8 ms 6272 KB correct
7 Correct 8 ms 6272 KB correct
8 Correct 8 ms 6272 KB correct
9 Correct 8 ms 6272 KB correct
10 Correct 8 ms 6272 KB correct
11 Correct 8 ms 6272 KB correct
12 Correct 8 ms 6272 KB correct
13 Correct 9 ms 6272 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6272 KB correct
2 Correct 8 ms 6272 KB correct
3 Correct 8 ms 6272 KB correct
4 Correct 8 ms 6272 KB correct
5 Correct 8 ms 6272 KB correct
6 Correct 8 ms 6272 KB correct
7 Correct 8 ms 6272 KB correct
8 Correct 8 ms 6272 KB correct
9 Correct 8 ms 6272 KB correct
10 Correct 8 ms 6272 KB correct
11 Correct 8 ms 6272 KB correct
12 Correct 8 ms 6272 KB correct
13 Correct 9 ms 6272 KB correct
14 Correct 71 ms 12408 KB correct
15 Correct 72 ms 12408 KB correct
16 Correct 74 ms 12536 KB correct
17 Correct 61 ms 11256 KB correct
18 Correct 25 ms 7936 KB correct
19 Correct 59 ms 11256 KB correct
20 Correct 56 ms 11000 KB correct
21 Correct 57 ms 10872 KB correct
22 Correct 27 ms 8448 KB correct
23 Correct 24 ms 7936 KB correct
24 Correct 22 ms 7652 KB correct
25 Correct 8 ms 6272 KB correct
26 Correct 22 ms 7680 KB correct
27 Correct 24 ms 7936 KB correct
28 Correct 11 ms 6528 KB correct
29 Correct 10 ms 6400 KB correct
30 Correct 38 ms 9208 KB correct
31 Correct 37 ms 9208 KB correct
32 Correct 37 ms 9208 KB correct
33 Correct 38 ms 9212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6272 KB correct
2 Correct 8 ms 6272 KB correct
3 Correct 8 ms 6272 KB correct
4 Correct 8 ms 6272 KB correct
5 Correct 8 ms 6272 KB correct
6 Correct 8 ms 6272 KB correct
7 Correct 8 ms 6272 KB correct
8 Correct 8 ms 6272 KB correct
9 Correct 8 ms 6272 KB correct
10 Correct 8 ms 6272 KB correct
11 Correct 8 ms 6272 KB correct
12 Correct 8 ms 6272 KB correct
13 Correct 9 ms 6272 KB correct
14 Correct 71 ms 12408 KB correct
15 Correct 72 ms 12408 KB correct
16 Correct 74 ms 12536 KB correct
17 Correct 61 ms 11256 KB correct
18 Correct 25 ms 7936 KB correct
19 Correct 59 ms 11256 KB correct
20 Correct 56 ms 11000 KB correct
21 Correct 57 ms 10872 KB correct
22 Correct 27 ms 8448 KB correct
23 Correct 24 ms 7936 KB correct
24 Correct 22 ms 7652 KB correct
25 Correct 8 ms 6272 KB correct
26 Correct 22 ms 7680 KB correct
27 Correct 24 ms 7936 KB correct
28 Correct 11 ms 6528 KB correct
29 Correct 10 ms 6400 KB correct
30 Correct 38 ms 9208 KB correct
31 Correct 37 ms 9208 KB correct
32 Correct 37 ms 9208 KB correct
33 Correct 38 ms 9212 KB correct
34 Incorrect 372 ms 38648 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6272 KB correct
2 Correct 8 ms 6272 KB correct
3 Incorrect 244 ms 29560 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6272 KB correct
2 Correct 8 ms 6272 KB correct
3 Correct 8 ms 6272 KB correct
4 Correct 8 ms 6272 KB correct
5 Correct 8 ms 6272 KB correct
6 Correct 8 ms 6272 KB correct
7 Correct 8 ms 6272 KB correct
8 Correct 8 ms 6272 KB correct
9 Correct 8 ms 6272 KB correct
10 Correct 8 ms 6272 KB correct
11 Correct 8 ms 6272 KB correct
12 Correct 8 ms 6272 KB correct
13 Correct 9 ms 6272 KB correct
14 Correct 71 ms 12408 KB correct
15 Correct 72 ms 12408 KB correct
16 Correct 74 ms 12536 KB correct
17 Correct 61 ms 11256 KB correct
18 Correct 25 ms 7936 KB correct
19 Correct 59 ms 11256 KB correct
20 Correct 56 ms 11000 KB correct
21 Correct 57 ms 10872 KB correct
22 Correct 27 ms 8448 KB correct
23 Correct 24 ms 7936 KB correct
24 Correct 22 ms 7652 KB correct
25 Correct 8 ms 6272 KB correct
26 Correct 22 ms 7680 KB correct
27 Correct 24 ms 7936 KB correct
28 Correct 11 ms 6528 KB correct
29 Correct 10 ms 6400 KB correct
30 Correct 38 ms 9208 KB correct
31 Correct 37 ms 9208 KB correct
32 Correct 37 ms 9208 KB correct
33 Correct 38 ms 9212 KB correct
34 Incorrect 372 ms 38648 KB WA in grader: NO
35 Halted 0 ms 0 KB -