Submission #817771

# Submission time Handle Problem Language Result Execution time Memory
817771 2023-08-09T16:05:42 Z oneloveforever Designated Cities (JOI19_designated_cities) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,q;
struct edge
{
    int x,value_x,value_y;
    edge(int _x=0,int _value_x=0,int _value_y=0)
    {
        x=_x,value_x=_value_x,value_y=_value_y;
    }
};
vector<vector<edge> >a;
struct SUB1
{
    int n;
    vector<int>num_child,num_par;
    SUB1(int _n=0)
    {
        n=_n;
        num_child.resize(n+7);
        num_par.resize(n+7);
    }
    void dfs_down(int x,int par)
    {
        for(edge need:a[x])
        {
            int node=need.x;
            int value_x=need.value_x;
            int value_y=need.value_y;
            if(node==par)continue;
            dfs_down(node,x);
            num_child[x]+=num_child[node]+value_x;
        }
    }
    void dfs_up(int x,int par)
    {
        for(edge need:a[x])
        {
            int node=need.x;
            int value_x=need.value_x;
            int value_y=need.value_y;
            if(node==par)continue;
            int value=num_child[x]-num_child[node];
            value+=num_par[x]+value_y;
            num_par[node]=value;
            dfs_up(node,x);
        }
    }
    void calc()
    {
        dfs_down(1,0);
        dfs_up(1,0);
        int ans=num_child[1];
        for(int i=2;i<=n;i++)ans=min(ans,num_par[i]+num_child[i]);
        cout<<ans;
    }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    a.resize(n+7);
    for(int i=1;i<=n-1;i++)
    {
        int x,y,value_x,value_y;
        cin>>x>>y>>value_x>>value_y;
        a[x].push_back({y,value_x,value_y});
        a[y].push_back({x,value_y,value_x});
    }
    int q;
    cin>>q;
    if(q==1)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            SUB1 s(n);
            s.calc();
        }
    }
}

Compilation message

designated_cities.cpp: In member function 'void SUB1::dfs_down(int, int)':
designated_cities.cpp:30:17: warning: unused variable 'value_y' [-Wunused-variable]
   30 |             int value_y=need.value_y;
      |                 ^~~~~~~
designated_cities.cpp: In member function 'void SUB1::dfs_up(int, int)':
designated_cities.cpp:41:17: warning: unused variable 'value_x' [-Wunused-variable]
   41 |             int value_x=need.value_x;
      |                 ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -