제출 #1004552

#제출 시각아이디문제언어결과실행 시간메모리
1004552vjudge1Railway (BOI17_railway)C++17
0 / 100
1079 ms524288 KiB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 1e5+5;
vl g[sz], q[sz];
ll vis[sz], lev[sz], p[30][sz], dist[sz], par[sz];
set<ll>st[sz];
void dfs(ll node)
{
    vis[node] = 1;
    for(auto u : g[node])
    {
        if(vis[u])
            continue;
        p[0][u] = node;
        lev[u] = lev[node] + 1;
        par[u] = node;
        dfs(u);
    }
}
ll jump(ll x, ll k)
{
    for(ll i = 0; i < 27; i++)
    {
        if((k >> i) & 1)
            x = p[i][x];
    }
    return x;
}
ll lca(ll x, ll y)
{
    if(lev[x] > lev[y])
        swap(x, y);
    ll d = lev[y] - lev[x];
    y = jump(y, d);
    if(x == y)
        return y;
    else
    {
        for(ll i = 26; i >= 0; i--)
        {
            if(p[i][x] != p[i][y])
            {
                x = p[i][x];
                y = p[i][y];
            }
        }
        return p[0][x];
    }
}
void dfs2(ll node)
{
    vis[node] = 1;
    for(auto u : g[node])
    {
        if(vis[u])
            continue;
        dfs2(u);
        dist[node] += dist[u];
    }
}
void solve()
{
    ll n, m, k, i, j, l;
    cin >> n >> m >> k;
    vector<pll>vect;
    for(i = 1; i <= n - 1; i++)
    {
        ll x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
        vect.pb({x, y});
    }
    dfs(1);
    for(i = 1; i < 27; i++)
    {
        for(j = 1; j <= n; j++)
            p[i][j] = p[i-1][p[i-1][j]];
    }
    ll cnt = 0;
    for(i = 1; i <= m; i++)
    {
        ll s;
        cin >> s;
        if(s == 2)
            cnt++;
        for(j = 1; j <= s; j++)
        {
            ll x;
            cin >> x;
            q[i].pb(x);
        }
    }
    /*if(cnt == m)
    {
        for(i = 1; i <= m; i++)
        {
            ll x = q[i][0], y = q[i][1];
            ll a = lca(x, y);
            dist[x]++;
            dist[y]++;
            dist[a]--;
            if(a != x && a != y)
                dist[par[a]] -= 2;
            else
                dist[par[a]]--;
        }
        for(i = 1; i <= n; i++)
            vis[i] = 0;
        dfs2(1);
        vl f;
        for(i = 0; i < vect.size(); i++)
        {
            ll x = vect[i].f, y = vect[i].s;
            if(min(dist[x], dist[y]) >= k)
                f.pb(i+1);
        }
        cout << f.size() << "\n";
        for(auto u : f)
            cout << u << ' ';
        cout << "\n";
    }
    else
    {*/
        for(i = 1; i <= m; i++)
        {
            for(j = 1; j <= n; j++)
                dist[j] = 0;
            for(j = 0; j < q[i].size(); j++)
            {
                for(l = j + 1; l < q[i].size(); l++)
                {
                    ll x = q[i][j], y = q[i][l];
                    ll a = lca(x, y);
                    dist[x]++;
                    dist[y]++;
                    dist[a]--;
                    if(a != x && a != y)
                        dist[par[a]] -= 2;
                    else
                        dist[par[a]]--;
                }
            }
            for(j = 1; j <= n; j++)
                vis[j] = 0;
            dfs2(1);
            for(j = 0; j < vect.size(); j++)
            {
                ll x = vect[j].f, y = vect[j].s;
                if(min(dist[x], dist[y]) > 0)
                    st[j].insert(i);
            }
        }
        vl f;
        for(j = 0; j < vect.size(); j++)
        {
            if(st[j].size() >= k)
                f.pb(j+1);
        }
        cout << f.size() << "\n";
        for(auto u : f)
            cout << u << ' ';
        cout << "\n";
    //}
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

railway.cpp: In function 'void solve()':
railway.cpp:146:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |             for(j = 0; j < q[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~
railway.cpp:148:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |                 for(l = j + 1; l < q[i].size(); l++)
      |                                ~~^~~~~~~~~~~~~
railway.cpp:164:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |             for(j = 0; j < vect.size(); j++)
      |                        ~~^~~~~~~~~~~~~
railway.cpp:172:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |         for(j = 0; j < vect.size(); j++)
      |                    ~~^~~~~~~~~~~~~
railway.cpp:174:29: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  174 |             if(st[j].size() >= k)
      |                ~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...