Submission #297873

# Submission time Handle Problem Language Result Execution time Memory
297873 2020-09-12T05:50:19 Z Autoratch Simurgh (IOI17_simurgh) C++14
51 / 100
176 ms 4472 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 501;

int n,m;
vector<pair<int,int> > adj[N];
vector<int> r,ans,tmp,ask,tmp2;
bool visited[N],computed[N*N];
vector<vector<int> > cmp;
int ed[N][N];
set<int> ts;

void dfs(int u,int f)
{
    if(visited[u]) return;
    visited[u] = true;
    tmp.push_back(u);
    for(auto [id,v] : adj[u]) if(!visited[v] and v!=f) r.push_back(id),dfs(v,f);
}

std::vector<int> find_roads(int _n, std::vector<int> u, std::vector<int> v) 
{
    n = _n,m = u.size();
    for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) ed[i][j] = -1;
    for(int i = 0;i < m;i++)
    {
        int a = u[i],b = v[i];
        adj[a].push_back({i,b});
        adj[b].push_back({i,a});
        ed[a][b] = ed[b][a] = i;
    }
    for(int i = 0;i < n;i++)
    {
        r.clear();
        tmp.clear();
        cmp.clear();
        for(int j = 0;j < n;j++) visited[j] = false;
        for(int j = 0;j < n;j++) if(!visited[j] and j!=i) dfs(j,i),cmp.push_back(tmp),tmp.clear();
        int cm = cmp.size();
        for(int j = 0;j < cm;j++) 
        {
            tmp.clear();
            for(int x : cmp[j]) if(ed[i][x]!=-1) tmp.push_back(ed[i][x]);
            swap(cmp[j],tmp);
        }
        for(int j = 0;j < cm;j++) 
        {
            tmp.clear();
            tmp = r;
            for(int k = 0;k < cm;k++) if(k!=j) tmp.push_back(cmp[k][0]);
            int mx = -1;
            tmp2.clear();
            bool used = false;
            for(int x : cmp[j]) 
            {
                if(computed[x])
                {
                    if(ts.find(x)!=ts.end() and !used) used = true;
                    else continue;
                }
                computed[x] = true;
                ask = tmp;
                ask.push_back(x);
                int ret = count_common_roads(ask);
                if(ret>mx) mx = ret,tmp2.clear(),tmp2.push_back(x);
                else if(ret==mx) tmp2.push_back(x);
            }
            for(int x : tmp2) ts.insert(x);
        }        
    }
    for(int x : ts) ans.push_back(x);
    return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs(int, int)':
simurgh.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |     for(auto [id,v] : adj[u]) if(!visited[v] and v!=f) r.push_back(id),dfs(v,f);
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 0 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 0 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 2 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 2 ms 512 KB correct
18 Correct 2 ms 512 KB correct
19 Correct 2 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 512 KB correct
22 Correct 2 ms 512 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 512 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 512 KB correct
27 Correct 2 ms 512 KB correct
28 Correct 1 ms 512 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 512 KB correct
31 Correct 2 ms 512 KB correct
32 Correct 2 ms 512 KB correct
33 Correct 2 ms 512 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 0 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 2 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 2 ms 512 KB correct
18 Correct 2 ms 512 KB correct
19 Correct 2 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 512 KB correct
22 Correct 2 ms 512 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 512 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 512 KB correct
27 Correct 2 ms 512 KB correct
28 Correct 1 ms 512 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 512 KB correct
31 Correct 2 ms 512 KB correct
32 Correct 2 ms 512 KB correct
33 Correct 2 ms 512 KB correct
34 Correct 170 ms 2048 KB correct
35 Correct 163 ms 2048 KB correct
36 Correct 116 ms 1792 KB correct
37 Correct 11 ms 896 KB correct
38 Correct 174 ms 2048 KB correct
39 Correct 144 ms 1920 KB correct
40 Correct 113 ms 1792 KB correct
41 Correct 174 ms 2048 KB correct
42 Correct 176 ms 2048 KB correct
43 Correct 98 ms 1664 KB correct
44 Correct 77 ms 1408 KB correct
45 Correct 87 ms 1408 KB correct
46 Correct 67 ms 1280 KB correct
47 Correct 32 ms 1144 KB correct
48 Correct 6 ms 896 KB correct
49 Correct 12 ms 896 KB correct
50 Correct 31 ms 1024 KB correct
51 Correct 87 ms 1528 KB correct
52 Correct 74 ms 1528 KB correct
53 Correct 67 ms 1280 KB correct
54 Correct 95 ms 1664 KB correct
55 Correct 84 ms 1408 KB correct
56 Correct 84 ms 1408 KB correct
57 Correct 84 ms 1408 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 392 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 125 ms 4472 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 0 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 512 KB correct
15 Correct 2 ms 512 KB correct
16 Correct 3 ms 512 KB correct
17 Correct 2 ms 512 KB correct
18 Correct 2 ms 512 KB correct
19 Correct 2 ms 512 KB correct
20 Correct 2 ms 512 KB correct
21 Correct 3 ms 512 KB correct
22 Correct 2 ms 512 KB correct
23 Correct 2 ms 512 KB correct
24 Correct 2 ms 512 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 512 KB correct
27 Correct 2 ms 512 KB correct
28 Correct 1 ms 512 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 512 KB correct
31 Correct 2 ms 512 KB correct
32 Correct 2 ms 512 KB correct
33 Correct 2 ms 512 KB correct
34 Correct 170 ms 2048 KB correct
35 Correct 163 ms 2048 KB correct
36 Correct 116 ms 1792 KB correct
37 Correct 11 ms 896 KB correct
38 Correct 174 ms 2048 KB correct
39 Correct 144 ms 1920 KB correct
40 Correct 113 ms 1792 KB correct
41 Correct 174 ms 2048 KB correct
42 Correct 176 ms 2048 KB correct
43 Correct 98 ms 1664 KB correct
44 Correct 77 ms 1408 KB correct
45 Correct 87 ms 1408 KB correct
46 Correct 67 ms 1280 KB correct
47 Correct 32 ms 1144 KB correct
48 Correct 6 ms 896 KB correct
49 Correct 12 ms 896 KB correct
50 Correct 31 ms 1024 KB correct
51 Correct 87 ms 1528 KB correct
52 Correct 74 ms 1528 KB correct
53 Correct 67 ms 1280 KB correct
54 Correct 95 ms 1664 KB correct
55 Correct 84 ms 1408 KB correct
56 Correct 84 ms 1408 KB correct
57 Correct 84 ms 1408 KB correct
58 Correct 1 ms 392 KB correct
59 Correct 1 ms 384 KB correct
60 Incorrect 125 ms 4472 KB WA in grader: NO
61 Halted 0 ms 0 KB -