Submission #577503

# Submission time Handle Problem Language Result Execution time Memory
577503 2022-06-14T22:29:14 Z definitelynotmee Simurgh (IOI17_simurgh) C++
51 / 100
117 ms 3500 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const int INF = 1e7;

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
    int m = u.size();
    
    matrix<pii> g(n);
    for(int i = 0; i < m; i++){
        g[u[i]].push_back({v[i],i});
        g[v[i]].push_back({u[i],i});
    }

    vector<int> royal, dfstree;
    dfstree.reserve(n);
    royal.reserve(n);

    vector<int> check(n), tin(n);
    int timer = -1;

    auto gettree =[&](int id, auto dfs)->void{
        check[id] = 1;
        tin[id] = ++timer;
        for(auto [viz,edge] : g[id]){
            if(!check[viz]){
                dfstree.push_back(edge);
                dfs(viz,dfs);
            }
        }
    };

    gettree(0,gettree);
    // for(int i : dfstree){
    //     cout << "->" << u[i] << ' ' << v[i] << '\n';
    // }
    fill(all(check),0);

    auto test =[&](int id, int remove){
        vector<int> query = dfstree;
        for(int& i : query){
            if(i == remove){
                i = id;
                break;
            }
        }
        return count_common_roads(query);

    };

    auto dfs =[&](int id, int last, auto dfs)->pii{
        check[id] = 1;
        pii back = {INF,0};
        for(auto [viz,edge] : g[id]){
            if(!check[viz]){
                back = min(back,dfs(viz,edge,dfs));
            }
        }
        if(last == -1)
            return {0,0};

        int resp = back.ff >= tin[id] ? 0 : test(back.ss,last);
        vector<int> child(g[id].size());

        for(int i = 0; i < g[id].size(); i++){
            int viz = g[id][i].ff, edge = g[id][i].ss;
            if(tin[viz] > tin[id])
                continue;
            child[i] = test(edge,last);
            resp = max(resp,child[i]);
        }

        for(int i = 0; i < g[id].size(); i++){
            int viz = g[id][i].ff, edge = g[id][i].ss;
            if(tin[viz] > tin[id])
                continue;
            if(child[i] == resp){
                back = min(back,{tin[viz],edge});
                royal.push_back(edge);
            }
        }
        return back;
    };
    dfs(0,-1,dfs);

    return royal;
}

Compilation message

simurgh.cpp: In lambda function:
simurgh.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         for(auto [viz,edge] : g[id]){
      |                  ^
simurgh.cpp: In lambda function:
simurgh.cpp:62:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         for(auto [viz,edge] : g[id]){
      |                  ^
simurgh.cpp: In instantiation of 'find_roads(int, std::vector<int>, std::vector<int>)::<lambda(int, int, auto:2)> [with auto:2 = find_roads(int, std::vector<int>, std::vector<int>)::<lambda(int, int, auto:2)>; pii = std::pair<int, int>]':
simurgh.cpp:92:17:   required from here
simurgh.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int i = 0; i < g[id].size(); i++){
      |                        ~~^~~~~~~~~~~~~~
simurgh.cpp:81:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i = 0; i < g[id].size(); i++){
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 300 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 296 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 300 KB correct
13 Correct 1 ms 300 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 300 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 296 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 300 KB correct
13 Correct 1 ms 300 KB correct
14 Correct 2 ms 304 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 304 KB correct
24 Correct 1 ms 308 KB correct
25 Correct 0 ms 304 KB correct
26 Correct 1 ms 300 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 300 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 300 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 296 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 300 KB correct
13 Correct 1 ms 300 KB correct
14 Correct 2 ms 304 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 304 KB correct
24 Correct 1 ms 308 KB correct
25 Correct 0 ms 304 KB correct
26 Correct 1 ms 300 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 300 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 116 ms 1576 KB correct
35 Correct 117 ms 1544 KB correct
36 Correct 79 ms 1360 KB correct
37 Correct 6 ms 312 KB correct
38 Correct 115 ms 1492 KB correct
39 Correct 98 ms 1460 KB correct
40 Correct 76 ms 1344 KB correct
41 Correct 116 ms 1492 KB correct
42 Correct 114 ms 1612 KB correct
43 Correct 62 ms 1108 KB correct
44 Correct 51 ms 888 KB correct
45 Correct 60 ms 940 KB correct
46 Correct 48 ms 724 KB correct
47 Correct 21 ms 468 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 7 ms 308 KB correct
50 Correct 22 ms 468 KB correct
51 Correct 59 ms 944 KB correct
52 Correct 49 ms 872 KB correct
53 Correct 43 ms 832 KB correct
54 Correct 63 ms 1136 KB correct
55 Correct 57 ms 980 KB correct
56 Correct 58 ms 980 KB correct
57 Correct 59 ms 980 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 1 ms 212 KB correct
3 Incorrect 96 ms 3500 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 300 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 296 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 300 KB correct
13 Correct 1 ms 300 KB correct
14 Correct 2 ms 304 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 304 KB correct
24 Correct 1 ms 308 KB correct
25 Correct 0 ms 304 KB correct
26 Correct 1 ms 300 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 300 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 116 ms 1576 KB correct
35 Correct 117 ms 1544 KB correct
36 Correct 79 ms 1360 KB correct
37 Correct 6 ms 312 KB correct
38 Correct 115 ms 1492 KB correct
39 Correct 98 ms 1460 KB correct
40 Correct 76 ms 1344 KB correct
41 Correct 116 ms 1492 KB correct
42 Correct 114 ms 1612 KB correct
43 Correct 62 ms 1108 KB correct
44 Correct 51 ms 888 KB correct
45 Correct 60 ms 940 KB correct
46 Correct 48 ms 724 KB correct
47 Correct 21 ms 468 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 7 ms 308 KB correct
50 Correct 22 ms 468 KB correct
51 Correct 59 ms 944 KB correct
52 Correct 49 ms 872 KB correct
53 Correct 43 ms 832 KB correct
54 Correct 63 ms 1136 KB correct
55 Correct 57 ms 980 KB correct
56 Correct 58 ms 980 KB correct
57 Correct 59 ms 980 KB correct
58 Correct 0 ms 256 KB correct
59 Correct 1 ms 212 KB correct
60 Incorrect 96 ms 3500 KB WA in grader: NO
61 Halted 0 ms 0 KB -