답안 #131121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131121 2019-07-16T14:57:14 Z nikolapesic2802 Uzastopni (COCI15_uzastopni) C++14
160 / 160
136 ms 26232 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

const int N=1e4+4,L=101;
vector<vector<int> > graf(N);
vector<int> v(N);
vector<pair<int,int> > calc(int tr,int par)
{
    vector<vector<int> > nxt(L);
    nxt[v[tr]].pb(v[tr]+1);
    for(auto p:graf[tr])
    {
        if(p==par)
            continue;
        auto sol=calc(p,tr);
        for(auto p:sol)
            if(p.f>v[tr]||p.s<=v[tr])
                nxt[p.f].pb(p.s);
    }
    vector<int> visited(L),no;
    vector<pair<int,int> > sol;
    for(int i=0;i<=v[tr];i++)
    {
        queue<int> q;
        q.push(i);
        visited[i]=1;
        no.pb(i);
        while(q.size())
        {
            int tr=q.front();
            q.pop();
            for(auto p:nxt[tr])
                if(!visited[p])
                    visited[p]=1,no.pb(p),q.push(p);
        }
        for(int j=1;j<(int)no.size();j++)
            if(no[j]>v[tr])
                sol.pb({i,no[j]});
        for(auto p:no)
            visited[p]=0;
        no.clear();
    }
    return sol;
}
int main()
{
	int n,a,b;
	scanf("%i",&n);
	for(int i=0;i<n;i++)
        scanf("%i",&v[i]),v[i]--;
    for(int i=1;i<n;i++)
        scanf("%i %i",&a,&b),a--,b--,graf[a].pb(b),graf[b].pb(a);
    auto sol=calc(0,0);
    printf("%i\n",sol.size());
    return 0;
}

Compilation message

uzastopni.cpp: In function 'int main()':
uzastopni.cpp:77:29: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%i\n",sol.size());
                   ~~~~~~~~~~^
uzastopni.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
uzastopni.cpp:73:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&v[i]),v[i]--;
         ~~~~~~~~~~~~~~~~~^~~~~~~
uzastopni.cpp:75:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&a,&b),a--,b--,graf[a].pb(b),graf[b].pb(a);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 4 ms 764 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 29 ms 1016 KB Output is correct
12 Correct 26 ms 1016 KB Output is correct
13 Correct 23 ms 1016 KB Output is correct
14 Correct 135 ms 26232 KB Output is correct
15 Correct 136 ms 26232 KB Output is correct
16 Correct 136 ms 26232 KB Output is correct
17 Correct 23 ms 1016 KB Output is correct
18 Correct 22 ms 1016 KB Output is correct
19 Correct 73 ms 1016 KB Output is correct
20 Correct 72 ms 1016 KB Output is correct