Submission #593721

# Submission time Handle Problem Language Result Execution time Memory
593721 2022-07-11T14:03:41 Z keta_tsimakuridze Simurgh (IOI17_simurgh) C++14
13 / 100
3000 ms 8020 KB
#include "simurgh.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
const int N = 505;
int f[N], t[N], CNT, P[N], h[N], Nn, up[N];
pii mn[N];
vector<int> golden;
vector<pii> V[N], adj[N];
vector<int> edges;
void dfs0(int u, int p) {
    f[u] = 1;
    for(int i = 0; i < V[u].size(); i++) {
        if(V[u][i].f == p) continue;
        if(!f[V[u][i].f]) {
            dfs0(V[u][i].f, u); //cout << "++" << V[u][i].s << endl;
            edges.push_back(V[u][i].s);
            t[V[u][i].s] = 1;
        }
    }
}
int rem(int e1, int e2) {
    vector<int> x;
    for(int i = 0; i < edges.size(); i++) {
        if(e1 != edges[i]) x.push_back(edges[i]);
    }
    x.push_back(e2);
    return count_common_roads(x) - CNT;
}
void add(int a, int b, int x) {
    adj[a].push_back({b, x});
    adj[b].push_back({a, -x});

}
void dfs(int u, int p) {
    mn[u] = {Nn + 1, 0};
    P[u] = p;
    if(u) h[u] = h[p] + 1; //cout << u << endl;
    for(int i = 0; i < V[u].size(); i++) {
        int e = V[u][i].s, v = V[u][i].f;
        if(v == p) continue;
        if(t[e]) {
            up[v] = e;
            dfs(v, u);
            if(mn[v].f > h[u]) golden[e] = 1;
            else add(e, mn[v].s, rem(e, mn[v].s));
            mn[u] = min(mn[u], mn[v]);
        } else if(h[v] < h[u]) {
            int x = u;
            while(P[x] != v) {
                x = P[x];
            }
            add(up[x], e, rem(up[x], e));
            mn[u] = min(mn[u], {h[v], e});
        }
    }
}
std::vector<int> find_roads(int nn, std::vector<int> u, std::vector<int> vv) {
    int m = u.size(); Nn = nn;
    golden.resize(m);
    for(int i = 0; i < m; i++) {
        V[u[i]].push_back({vv[i], i});
        V[vv[i]].push_back({u[i], i});
    }
    dfs0(0, -1); // 0dan iwyeba?
    CNT = count_common_roads(edges);
    dfs(0, -1);
    vector<int> vis(m);
    for(int i = 0; i < m; i++) {
        if(!vis[i]) {
            queue<int> q;
            q.push(i);
            h[i] = 0;
            int mx = 0;
            vector<int> x;
            while(q.size()) {
                int u = q.front(); q.pop();
                mx = max(mx, h[u]);
                for(int j = 0; j < adj[u].size(); j++) {
                    if(vis[adj[u][j].f]) continue;
                    h[adj[u][j].f] = h[u] + adj[u][j].s;
                    vis[adj[u][j].f] = 1;
                    q.push(adj[u][j].f);
                }
                x.push_back(u);
            }
            for(int j = 0; j < x.size(); j++) if(h[x[j]] == mx) golden[x[j]] = 1;
        }
    }
    vector<int> ans;
    for(int i = 0; i < m; i++) {
        if(golden[i]) ans.push_back(i);
    }
    return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs0(int, int)':
simurgh.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
simurgh.cpp: In function 'int rem(int, int)':
simurgh.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < edges.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
simurgh.cpp: In function 'void dfs(int, int)':
simurgh.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:81:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                 for(int j = 0; j < adj[u].size(); j++) {
      |                                ~~^~~~~~~~~~~~~~~
simurgh.cpp:89:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for(int j = 0; j < x.size(); j++) if(h[x[j]] == mx) golden[x[j]] = 1;
      |                            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 0 ms 340 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 0 ms 340 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 0 ms 340 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 0 ms 340 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 340 KB correct
14 Execution timed out 3064 ms 340 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 0 ms 340 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 0 ms 340 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 340 KB correct
14 Execution timed out 3064 ms 340 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Runtime error 20 ms 8020 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 0 ms 340 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 0 ms 340 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 340 KB correct
14 Execution timed out 3064 ms 340 KB Time limit exceeded
15 Halted 0 ms 0 KB -