답안 #1075706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075706 2024-08-26T08:45:14 Z amin Simurgh (IOI17_simurgh) C++14
51 / 100
98 ms 2604 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)
{
    x=par(x);
    y=par(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:31:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while(ans.size()<n-1)
      |           ~~~~~~~~~~^~~~
simurgh.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int i=0; i<ans.size(); i++)
      |                      ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 344 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 344 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 344 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 352 KB correct
32 Correct 1 ms 344 KB correct
33 Correct 1 ms 448 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 344 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 344 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 352 KB correct
32 Correct 1 ms 344 KB correct
33 Correct 1 ms 448 KB correct
34 Correct 89 ms 1192 KB correct
35 Correct 90 ms 1172 KB correct
36 Correct 64 ms 936 KB correct
37 Correct 5 ms 492 KB correct
38 Correct 98 ms 1116 KB correct
39 Correct 82 ms 856 KB correct
40 Correct 62 ms 856 KB correct
41 Correct 84 ms 1112 KB correct
42 Correct 81 ms 1116 KB correct
43 Correct 14 ms 604 KB correct
44 Correct 12 ms 604 KB correct
45 Correct 13 ms 648 KB correct
46 Correct 11 ms 604 KB correct
47 Correct 6 ms 580 KB correct
48 Correct 2 ms 464 KB correct
49 Correct 3 ms 348 KB correct
50 Correct 6 ms 348 KB correct
51 Correct 14 ms 600 KB correct
52 Correct 13 ms 604 KB correct
53 Correct 11 ms 604 KB correct
54 Correct 15 ms 604 KB correct
55 Correct 14 ms 792 KB correct
56 Correct 14 ms 600 KB correct
57 Correct 15 ms 656 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 78 ms 2604 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 344 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 344 KB correct
27 Correct 1 ms 344 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 352 KB correct
32 Correct 1 ms 344 KB correct
33 Correct 1 ms 448 KB correct
34 Correct 89 ms 1192 KB correct
35 Correct 90 ms 1172 KB correct
36 Correct 64 ms 936 KB correct
37 Correct 5 ms 492 KB correct
38 Correct 98 ms 1116 KB correct
39 Correct 82 ms 856 KB correct
40 Correct 62 ms 856 KB correct
41 Correct 84 ms 1112 KB correct
42 Correct 81 ms 1116 KB correct
43 Correct 14 ms 604 KB correct
44 Correct 12 ms 604 KB correct
45 Correct 13 ms 648 KB correct
46 Correct 11 ms 604 KB correct
47 Correct 6 ms 580 KB correct
48 Correct 2 ms 464 KB correct
49 Correct 3 ms 348 KB correct
50 Correct 6 ms 348 KB correct
51 Correct 14 ms 600 KB correct
52 Correct 13 ms 604 KB correct
53 Correct 11 ms 604 KB correct
54 Correct 15 ms 604 KB correct
55 Correct 14 ms 792 KB correct
56 Correct 14 ms 600 KB correct
57 Correct 15 ms 656 KB correct
58 Correct 1 ms 344 KB correct
59 Correct 0 ms 348 KB correct
60 Incorrect 78 ms 2604 KB WA in grader: NO
61 Halted 0 ms 0 KB -