Submission #827086

# Submission time Handle Problem Language Result Execution time Memory
827086 2023-08-16T08:38:12 Z vnm06 Simurgh (IOI17_simurgh) C++14
0 / 100
1143 ms 1972 KB
#include<bits/stdc++.h>
#include "simurgh.h"

using namespace std;

int sg=0;
int par[500], db[500];
bool prov[500000];
int ans[500000];
vector<int> added_edges;

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
    int m=u.size();
    for(int i=0; i<n; i++)
    {
        ///for(int j=0; j<sg; j++) //cout<<added_edges[j]<<" ";
        //cout<<endl;
        if(added_edges.size()==n-1) return added_edges;
        for(int i=0; i<n; i++)
        {
            par[i]=i;
            db[i]=1;
        }
        for(int j=0; j<sg; j++)
        {
            int v1=u[added_edges[j]], v2=v[added_edges[j]];
            while(v1!=par[v1]) v1=par[v1];
            while(v2!=par[v2]) v2=par[v2];
            if(db[v1]>db[v2]) par[v2]=v1;
            else if(db[v1]>db[v2]) par[v1]=v2;
            else
            {
                par[v2]=v1;
                db[v1]++;
            }
        }
        ///for(int i=0; i<n; i++) //cout<<par[i]<<endl;
        int cmp=i;
        while(cmp!=par[cmp]) cmp=par[cmp];
        for(int j=0; j<m; j++)
        {
            int v1=u[j], v2=v[j];
            while(v1!=par[v1]) v1=par[v1];
            while(v2!=par[v2]) v2=par[v2];
            if(v1==v2 || v1==cmp || v2==cmp) continue;
            added_edges.push_back(j);
            if(db[v1]>db[v2]) par[v2]=v1;
            else if(db[v1]>db[v2]) par[v1]=v2;
            else
            {
                par[v2]=v1;
                db[v1]++;
            }
        }
        int mist=1e9, mast=-1;
        for(int j=0; j<m; j++) ans[j]=-1;
        for(int j=0; j<m; j++)
        {
            if(prov[j]) continue;
            int v1=u[j], v2=v[j];
            while(v1!=par[v1]) v1=par[v1];
            while(v2!=par[v2]) v2=par[v2];
            if(v1!=cmp && v2!=cmp) continue;
            if(v1==v2) continue;
            prov[j]=1;
            added_edges.push_back(j);
            ans[j]=count_common_roads(added_edges);
            if(ans[j]>mast) mast=ans[j];
            if(ans[j]<mist) mist=ans[j];
            added_edges.resize(added_edges.size()-1);
        }
        added_edges.resize(sg);
        for(int j=0; j<m; j++)
        {
            if(ans[j]==mast)
            {
                added_edges.push_back(j);
                sg++;
            }
        }
    }
	return added_edges;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:19:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         if(added_edges.size()==n-1) return added_edges;
      |            ~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Incorrect 0 ms 212 KB WA in grader: NO
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Incorrect 0 ms 212 KB WA in grader: NO
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Incorrect 0 ms 212 KB WA in grader: NO
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Incorrect 1143 ms 1972 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Incorrect 0 ms 212 KB WA in grader: NO
12 Halted 0 ms 0 KB -