Submission #409580

# Submission time Handle Problem Language Result Execution time Memory
409580 2021-05-21T05:49:28 Z anime Fireworks (APIO16_fireworks) C++14
7 / 100
29 ms 47268 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%d %lld",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define umax(a,b) a = max(a,b);
#define umin(a,b) a = min(a,b);
#define endi puts("");
#define eps 1e-12
const int N = 1e6+12,INF=1e18+7;
int q[N],res;
vector <pii> g[N],ver[N];
void dfs(int x,int gl){
    if (g[x].empty())ret ;
    vector <vector <pii> > v(g[x].size());

    for (pii to:g[x]){
        dfs(to.fr,gl+1);
    }

    for (int i=0;i<g[x].size();++i){
        pii to = g[x][i];
        for (pii a:ver[to.fr]){
            a.fr += to.sc;
            v[i].pb(a);
        }
    }
    for (int i=0;i<g[x].size();++i){
        for (pii a:v[i]){
            int suma = 0;


            for (int j=0;j<g[x].size();++j){
                int sum = INF;

                for (pii b:v[j]){
                    sum = min(sum,abs(a.fr-b.fr)+b.sc);
                }
                if (v[j].empty()) sum =0;
                suma += sum;

            }
            ver[x].pb({a.fr,suma});
        }
    }

}


main(){
    int n,m,i,j,ans=INF,sum=0;
    cin>>n>>m;
    for (i=2;i<=m+n;++i){
        int x,y;
        cin>>x>>y;
        g[x].pb({i,y});
        if (i > n)
            ver[i].pb({0,0});
    }
    dfs(1,0);
    for (pii a:ver[1]){
        ans = min(ans,a.sc);
    }
    cout <<ans;
}



















Compilation message

fireworks.cpp: In function 'void dfs(long long int, long long int)':
fireworks.cpp:36:19: 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]
   36 |     for (int i=0;i<g[x].size();++i){
      |                  ~^~~~~~~~~~~~
fireworks.cpp:43:19: 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]
   43 |     for (int i=0;i<g[x].size();++i){
      |                  ~^~~~~~~~~~~~
fireworks.cpp:48:27: 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]
   48 |             for (int j=0;j<g[x].size();++j){
      |                          ~^~~~~~~~~~~~
fireworks.cpp: At global scope:
fireworks.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main(){
      | ^~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:66:15: warning: unused variable 'j' [-Wunused-variable]
   66 |     int n,m,i,j,ans=INF,sum=0;
      |               ^
fireworks.cpp:66:25: warning: unused variable 'sum' [-Wunused-variable]
   66 |     int n,m,i,j,ans=INF,sum=0;
      |                         ^~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47220 KB Output is correct
2 Correct 25 ms 47180 KB Output is correct
3 Correct 25 ms 47220 KB Output is correct
4 Correct 26 ms 47268 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 26 ms 47256 KB Output is correct
7 Correct 26 ms 47268 KB Output is correct
8 Correct 26 ms 47240 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 29 ms 47248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 47160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47220 KB Output is correct
2 Correct 25 ms 47180 KB Output is correct
3 Correct 25 ms 47220 KB Output is correct
4 Correct 26 ms 47268 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 26 ms 47256 KB Output is correct
7 Correct 26 ms 47268 KB Output is correct
8 Correct 26 ms 47240 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 29 ms 47248 KB Output is correct
11 Incorrect 25 ms 47160 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47220 KB Output is correct
2 Correct 25 ms 47180 KB Output is correct
3 Correct 25 ms 47220 KB Output is correct
4 Correct 26 ms 47268 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 26 ms 47256 KB Output is correct
7 Correct 26 ms 47268 KB Output is correct
8 Correct 26 ms 47240 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 29 ms 47248 KB Output is correct
11 Incorrect 25 ms 47160 KB Output isn't correct
12 Halted 0 ms 0 KB -