답안 #283350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283350 2020-08-25T14:54:16 Z MKopchev Simurgh (IOI17_simurgh) C++14
51 / 100
280 ms 5788 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=500+42;
/*
int count_common_roads(vector<int> r)
{
    for(auto k:r)cout<<k<<" ";

    cout<<" -> ";

    int ret=0;

    for(auto k:r)
        if(k==0||k==1||k==5)ret++;
        //if(k==0||k==1||k==3)ret++;

    //cin>>ret;

    cout<<"ret= "<<ret<<endl;

    while(r.size()!=3)
    {
        while(1);
    }

    return ret;
}
*/
int type[nmax*nmax];//-1-> unknown, 0-> not special, 1-> special

int parent[nmax];
int root(int node)
{
    if(parent[node]==node)return node;
    parent[node]=root(parent[node]);
    return parent[node];
}

void init(int n_)
{
    for(int i=0;i<n_;i++)
        parent[i]=i;
}

vector< pair<int/*to*/,int/*id*/> > adj[nmax];

int is_forced[nmax*nmax];

vector<int> forced={};

vector< pair<int,int> > edges;

int my_n;

void dumb(int node)
{
    //cout<<"dumb "<<node<<endl;

    //for(int i=0;i<edges.size();i++)cout<<type[i]<<" ";cout<<endl;

    init(my_n);

    vector<int> cur_r=forced,to_solve={};

    for(auto k:forced)
        parent[root(edges[k].first)]=root(edges[k].second);

    int important=-1;

    for(auto k:adj[node])
        if(is_forced[k.second]==0&&type[k.second]!=-1)important=k.second;
        else if(type[k.second]==-1)to_solve.push_back(k.second);

    if(to_solve.size()==0)return;

    vector<int> to_run={};

    if(important!=-1)
    {
        for(int i=0;i<edges.size();i++)
            if(edges[i].first!=node&&edges[i].second!=node&&root(edges[i].first)!=root(edges[i].second))
            {
                parent[root(edges[i].first)]=root(edges[i].second);

                cur_r.push_back(i);
            }

        cur_r.push_back(important);

        int with=count_common_roads(cur_r);

        cur_r.pop_back();

        for(auto k:adj[node])
            if(type[k.second]==-1)
            {
                cur_r.push_back(k.second);

                int cur=count_common_roads(cur_r);

                cur_r.pop_back();

                type[k.second]=cur-with+type[important];

                to_run.push_back(k.first);
            }
    }
    else
    {
        for(int i=0;i<edges.size();i++)
            if(edges[i].first!=node&&edges[i].second!=node&&root(edges[i].first)!=root(edges[i].second))
            {
                parent[root(edges[i].first)]=root(edges[i].second);

                cur_r.push_back(i);

                //cout<<"push "<<i<<endl;
            }
        //cout<<"---"<<endl;

        vector<int> mem={},with={};

        for(auto k:adj[node])
            if(type[k.second]==-1)
            {
                //cout<<"k= "<<k.second<<endl;

                with.push_back(k.second);

                cur_r.push_back(k.second);

                mem.push_back(count_common_roads(cur_r));

                cur_r.pop_back();
            }

        int mini=mem[0],maxi=mem[0];

        for(auto k:mem)
        {
            mini=min(mini,k);
            maxi=max(maxi,k);
        }

        if(mini!=maxi)//mini=maxi => all are equal
        {
            for(int i=0;i<mem.size();i++)
            {
                to_run.push_back(adj[node][i].first);

                type[with[i]]=mem[i]-mini;
            }
        }

    }

    for(auto k:to_run)
        dumb(k);
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
    my_n=n;

    for(int i=0;i<u.size();i++)
        edges.push_back({u[i],v[i]});

    memset(type,-1,sizeof(type));

    vector<int> to_test={};

    init(n);

    for(int i=0;i<u.size();i++)
    {
        if(root(u[i])!=root(v[i]))
        {
            to_test.push_back(i);
            parent[root(u[i])]=root(v[i]);
        }

        adj[u[i]].push_back({v[i],i});
        adj[v[i]].push_back({u[i],i});
    }

    for(auto cur:to_test)
    {
        init(n);

        for(int i=0;i<u.size()&&root(u[cur])!=root(v[cur]);i++)
            if(root(u[i])!=root(v[i])&&i!=cur)
                parent[root(u[i])]=root(v[i]);

        if(root(u[cur])!=root(v[cur]))
        {
            type[cur]=1;
            forced.push_back(cur);
            is_forced[cur]=1;

            //cout<<"forced "<<cur<<endl;
        }
    }

    for(int i=0;i<n;i++)dumb(i);

    vector<int> ret={};

    for(int i=0;i<edges.size();i++)
        if(type[i]==1)ret.push_back(i);

    return ret;
}

Compilation message

simurgh.cpp: In function 'void dumb(int)':
simurgh.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int i=0;i<edges.size();i++)
      |                     ~^~~~~~~~~~~~~
simurgh.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for(int i=0;i<edges.size();i++)
      |                     ~^~~~~~~~~~~~~
simurgh.cpp:149:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |             for(int i=0;i<mem.size();i++)
      |                         ~^~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:166:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  166 |     for(int i=0;i<u.size();i++)
      |                 ~^~~~~~~~~
simurgh.cpp:175:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |     for(int i=0;i<u.size();i++)
      |                 ~^~~~~~~~~
simurgh.cpp:191:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  191 |         for(int i=0;i<u.size()&&root(u[cur])!=root(v[cur]);i++)
      |                     ~^~~~~~~~~
simurgh.cpp:209:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  209 |     for(int i=0;i<edges.size();i++)
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB correct
2 Correct 1 ms 1440 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 1 ms 1536 KB correct
6 Correct 1 ms 1536 KB correct
7 Correct 1 ms 1536 KB correct
8 Correct 1 ms 1536 KB correct
9 Correct 1 ms 1536 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 1536 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB correct
2 Correct 1 ms 1440 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 1 ms 1536 KB correct
6 Correct 1 ms 1536 KB correct
7 Correct 1 ms 1536 KB correct
8 Correct 1 ms 1536 KB correct
9 Correct 1 ms 1536 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 1536 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 4 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 5 ms 1664 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 4 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 3 ms 1536 KB correct
24 Correct 3 ms 1536 KB correct
25 Correct 1 ms 1536 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 2 ms 1536 KB correct
30 Correct 3 ms 1536 KB correct
31 Correct 3 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 3 ms 1536 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB correct
2 Correct 1 ms 1440 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 1 ms 1536 KB correct
6 Correct 1 ms 1536 KB correct
7 Correct 1 ms 1536 KB correct
8 Correct 1 ms 1536 KB correct
9 Correct 1 ms 1536 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 1536 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 4 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 5 ms 1664 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 4 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 3 ms 1536 KB correct
24 Correct 3 ms 1536 KB correct
25 Correct 1 ms 1536 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 2 ms 1536 KB correct
30 Correct 3 ms 1536 KB correct
31 Correct 3 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 3 ms 1536 KB correct
34 Correct 268 ms 3444 KB correct
35 Correct 273 ms 3472 KB correct
36 Correct 179 ms 3140 KB correct
37 Correct 19 ms 1792 KB correct
38 Correct 279 ms 3444 KB correct
39 Correct 239 ms 3464 KB correct
40 Correct 202 ms 3060 KB correct
41 Correct 280 ms 3572 KB correct
42 Correct 275 ms 3444 KB correct
43 Correct 154 ms 2684 KB correct
44 Correct 128 ms 2416 KB correct
45 Correct 132 ms 2424 KB correct
46 Correct 104 ms 2292 KB correct
47 Correct 49 ms 1792 KB correct
48 Correct 9 ms 1536 KB correct
49 Correct 18 ms 1792 KB correct
50 Correct 48 ms 1920 KB correct
51 Correct 138 ms 2452 KB correct
52 Correct 117 ms 2428 KB correct
53 Correct 109 ms 2444 KB correct
54 Correct 139 ms 2680 KB correct
55 Correct 126 ms 2680 KB correct
56 Correct 132 ms 2812 KB correct
57 Correct 119 ms 2660 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB correct
2 Correct 1 ms 1536 KB correct
3 Incorrect 184 ms 5788 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB correct
2 Correct 1 ms 1440 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 1 ms 1536 KB correct
6 Correct 1 ms 1536 KB correct
7 Correct 1 ms 1536 KB correct
8 Correct 1 ms 1536 KB correct
9 Correct 1 ms 1536 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 1536 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 4 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 5 ms 1664 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 4 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 3 ms 1536 KB correct
24 Correct 3 ms 1536 KB correct
25 Correct 1 ms 1536 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 2 ms 1536 KB correct
30 Correct 3 ms 1536 KB correct
31 Correct 3 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 3 ms 1536 KB correct
34 Correct 268 ms 3444 KB correct
35 Correct 273 ms 3472 KB correct
36 Correct 179 ms 3140 KB correct
37 Correct 19 ms 1792 KB correct
38 Correct 279 ms 3444 KB correct
39 Correct 239 ms 3464 KB correct
40 Correct 202 ms 3060 KB correct
41 Correct 280 ms 3572 KB correct
42 Correct 275 ms 3444 KB correct
43 Correct 154 ms 2684 KB correct
44 Correct 128 ms 2416 KB correct
45 Correct 132 ms 2424 KB correct
46 Correct 104 ms 2292 KB correct
47 Correct 49 ms 1792 KB correct
48 Correct 9 ms 1536 KB correct
49 Correct 18 ms 1792 KB correct
50 Correct 48 ms 1920 KB correct
51 Correct 138 ms 2452 KB correct
52 Correct 117 ms 2428 KB correct
53 Correct 109 ms 2444 KB correct
54 Correct 139 ms 2680 KB correct
55 Correct 126 ms 2680 KB correct
56 Correct 132 ms 2812 KB correct
57 Correct 119 ms 2660 KB correct
58 Correct 1 ms 1536 KB correct
59 Correct 1 ms 1536 KB correct
60 Incorrect 184 ms 5788 KB WA in grader: NO
61 Halted 0 ms 0 KB -