Submission #1075675

# Submission time Handle Problem Language Result Execution time Memory
1075675 2024-08-26T08:31:05 Z amin Simurgh (IOI17_simurgh) C++14
0 / 100
0 ms 348 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>adj;
vector<int>q;
int pa[1000000];
int mark[1000000];
int par(int x)
{

    if(pa[x]==x)
        return x;
    pa[x]=par(pa[x]);
    return pa[x];
}
void mer(int x,int y)
{
    if(x==y)
        return ;
    pa[y]=x;


}
vector<int> find_roads(int n, vector<int> u, vector<int> v)
{
    int m=v.size();
    vector<int>ans;

    while(ans.size()<n-1)
    {
      //  cout<<ans.size()<<endl;
        int no=n;
        q.clear();
        for(int i=0; i<n; i++)
            pa[i]=i;
        for(int i=0; i<ans.size(); i++)
        {

                q.push_back(ans[i]);
                mer(u[ans[i]],v[ans[i]]);


        }
        no=n-ans.size();

            for(int i=0; i<m; i++)
        {
            int x=u[i];
            int y=v[i];
            x=par(x);
            y=par(y);
            if(x!=y&&no>2)
            {
                q.push_back(i);
                no--;
                mer(x,y);

            }
        }

            int co=-1;
            stack<int>s;
            for(int i=0; i<m; i++)
        {
            int x=u[i];
            int y=v[i];
            x=par(x);
            y=par(y);
            if(mark[i]==0&&x!=y)
            {
                mark[i]=1;
                q.push_back(i);
              //  s.push(i);
               int j=count_common_roads(q);

               if(j!=co&&co!=-1)
               {
                   if(j>co)
                   {
                       while(!s.empty())
                       {
                           s.pop();
                       }
                       ans.push_back(i);
                   }else
                   {
                         while(!s.empty())
                       {
                           ans.push_back(s.top());

                           s.pop();
                       }
                   }
                   break;
               }
               s.push(i);
                co=j;
               q.pop_back();

            }

        }
         while(!s.empty())
                       {
                           ans.push_back(s.top());

                           s.pop();
                       }
    }

    return ans;


}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:29:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while(ans.size()<n-1)
      |           ~~~~~~~~~~^~~~
simurgh.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i=0; i<ans.size(); i++)
      |                      ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 0 ms 348 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 0 ms 348 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 0 ms 348 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 0 ms 348 KB WA in grader: NO
4 Halted 0 ms 0 KB -