답안 #293061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293061 2020-09-07T15:53:21 Z Saboon Simurgh (IOI17_simurgh) C++17
13 / 100
156 ms 4984 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 500 + 10;

vector<pair<int,int>> g[maxn];
int par[maxn], parindex[maxn], h[maxn];
bool visited[maxn];
int Cost, c[maxn*maxn];

void dfs(int v){
    visited[v] = 1;
    for (auto [u,idx] : g[v]){
        if (!visited[u]){
            h[u] = h[v]+1;
            par[u] = v;
            parindex[u] = idx;
            dfs(u);
        }
    }
}

bool eq[maxn];

vector<int> find_roads(int n, vector<int> u, vector<int> v){
    int m = v.size();
    for (int i = 0; i < v.size(); i++){
        g[v[i]].push_back({u[i],i});
        g[u[i]].push_back({v[i],i});
    }
    dfs(0);
    vector<int> Q(n-1);
    for (int i = 1; i < n; i++)
        Q[i-1] = parindex[i];
    Cost = count_common_roads(Q);
    memset(c, -1, sizeof c);
    for (int i = 0; i < m; i++){
        if (h[v[i]] > h[u[i]])
            swap(v[i],u[i]);
        if (par[u[i]] == v[i])
            continue;
        int x = u[i], me = -1;
        while (x != v[i]){
            if (c[parindex[x]] != -1 and me != -1){
                x = par[x];
                continue;
            }
            Q[x-1] = i;
            int Tmp = count_common_roads(Q);
            if (c[parindex[x]] != -1){
                if (Tmp == Cost)
                    me = c[parindex[x]];
                else
                    me = 1-c[parindex[x]];
           }
            else{
                if (Tmp == Cost)
                    eq[x] = 1;
                else if (Tmp > Cost)
                    eq[x] = 0, me = 1;
                else
                    eq[x] = 0, me = 0;
            }
            Q[x-1] = parindex[x];
            x = par[x];
        }
        if (me == -1)
            me = 0;
        x = u[i];
        while (x != v[i]){
            if (c[parindex[x]] == -1){
                if (eq[x])
                    c[parindex[x]] = me;
                else
                    c[parindex[x]] = 1-me;
            }
            x = par[x];
        }
        c[i] = me;
    }
    int now = 0;
    for (int i = 0; i < m; i++)
        if (c[i] == 1)
            Q[now++] = i;
    return Q;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < v.size(); i++){
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 2 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 2 ms 1312 KB correct
10 Correct 2 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 2 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 2 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 2 ms 1312 KB correct
10 Correct 2 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 2 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 3 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Incorrect 2 ms 1408 KB WA in grader: NO
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 2 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 2 ms 1312 KB correct
10 Correct 2 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 2 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 3 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Incorrect 2 ms 1408 KB WA in grader: NO
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Incorrect 156 ms 4984 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 2 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1408 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 2 ms 1312 KB correct
10 Correct 2 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 2 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 3 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 3 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Incorrect 2 ms 1408 KB WA in grader: NO
23 Halted 0 ms 0 KB -