답안 #963145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963145 2024-04-14T15:08:52 Z Amr 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
컴파일 오류
0 ms 0 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define sz size()
#define all(x) (x).begin(),(x).end()
const int N = 1002;
const int Log = 32;
vector<pair<ll,ll> > v[N];
ll lst[N];
vector<ll> vec;
ll vis[N];
pair<ll,ll> sp[N][Log][2];
void dfs1(ll x)
{
    if(vis[x]) return;
    vis[x] = 1;
    vec.push_back(x);
    for(int i = 0; i < v[x].sz; i++)
    {
        dfs1(v[x][i].S);
    }
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    for(int i = 0; i < M; i++)
    {
        ll x = R[i][0] , y = R[i][1];
        v[x].push_back({i,y});
        v[y].push_back({i,x});
    }
    for(int i = 0; i < N; i++) sort(all(v[i]));


    dfs1(P);
    if(vec.sz==2)
    {
        answer(1);
        return;
    }
    for(int i = 0; i < vec.sz; i++)
    {
        ll x = vec[i];
        ll y = v[x][0].S;
        ll m = -1;
        if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1;
        sp[x][0][0] = {y,m};


        if(v[x].sz==1) {sp[x][0][1] = {-1,-1}; continue;}

        m = -1;
        y = v[x][1].S;
        if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1;
        sp[x][0][1] = {y,m};
    }
    for(int j = 1; j < Log; j++)
    {
        for(int i = 0; i < vec.sz; i++)
        {
            ll x = vec[i];
            ll y = sp[x][j-1][0].F,m=0;
            if(v[y].sz>1&&sp[x][j-1][0].S==0) m = 1;
            sp[x][j][0] = sp[y][j-1][m];
            if(v[x].sz==1) continue;

                ll y = sp[x][j-1][1].F,m=-1;
                if(v[y].sz>1&&sp[x][j-1][1].S==0) m = 1;
                sp[x][j][1] = sp[y][j-1][m];
        }
    }
    /*for(int i = 0; i < N; i++){

        for(int j = 0; j < 3; j++)
        {
            cout << sp[i][j][0].F <<  " " << sp[i][j][1].F << endl;
        }
        cout << endl;
    }*/


        ll ans = 0;
        for(int i = 0; i < vec.sz; i++)
        {
            ll x = vec[i], y = 0;
            ll k = G[0];
            for(int j = Log-1; j >= 0; j--)
            {
                if(k<(1LL<<j)) continue;
                k-=(1LL<<j);
                ll x2 = sp[x][j][y].F,m = sp[x][j][y].S;
                if(m==0&&v[x2].sz>1) m = 1; else m = 0;
                x = x2, y = m;
            }
            //cout << x << " ";
            if(x==P) ans++;
        }
        answer(ans);


}

Compilation message

garden.cpp: In function 'void dfs1(ll)':
garden.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < v[x].sz; i++)
      |                      ^
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < vec.sz; i++)
      |                      ^
garden.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int i = 0; i < vec.sz; i++)
      |                          ^
garden.cpp:70:20: error: redeclaration of 'll y'
   70 |                 ll y = sp[x][j-1][1].F,m=-1;
      |                    ^
garden.cpp:65:16: note: 'll y' previously declared here
   65 |             ll y = sp[x][j-1][0].F,m=0;
      |                ^
garden.cpp:70:40: error: redeclaration of 'll m'
   70 |                 ll y = sp[x][j-1][1].F,m=-1;
      |                                        ^
garden.cpp:65:36: note: 'll m' previously declared here
   65 |             ll y = sp[x][j-1][0].F,m=0;
      |                                    ^
garden.cpp:86:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for(int i = 0; i < vec.sz; i++)
      |                          ^