Submission #1030553

# Submission time Handle Problem Language Result Execution time Memory
1030553 2024-07-22T06:47:55 Z 김은성(#10955) Designated Cities (JOI19_designated_cities) C++17
7 / 100
206 ms 46928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[200009];
bool ch[200009];
const ll INF = 0x3fffffffffffffff;
vector<pair<int, ll> > graph[200009];
vector<pair<int, ll> > tree[200009];
ll depth[200009], sum = 0, mn = 0;
int par[200009];
void construct_tree(int v){
    ch[v] = 1;
    for(int i=0; i<graph[v].size(); i++){
        int u = graph[v][i].first;
        if(!ch[u]){
            sum += graph[v][i].second;
            tree[v].push_back(graph[v][i]);
            par[u] = v;
            construct_tree(u);
        }
    }
}
int deepest_vertex(int v, ll d){
    depth[v] = d;
    ch[v] = 1;
    int ans = v;
    for(int i=0; i<tree[v].size(); i++){
        int u = tree[v][i].first;
        if(!ch[u]){
            int x = deepest_vertex(u, d+tree[v][i].second);
            if(depth[x] > depth[ans])
                ans = x;
        }
    }
    return ans;
}
void delete_edge(int v, int r){
    int p = par[v];
    while(v != r){
        for(int i=0; i<tree[p].size(); i++){
            if(tree[p][i].first == v)
                tree[p][i].second = 0;
        }
        v = p;
        p = par[v];
    }
}
void dfs(int v){
    ch[v] = 1;
    mn = min(mn, sum);
    for(int i=0; i<graph[v].size(); i++){
        int u = graph[v][i].first;
        if(ch[u])
            continue;
        ll c = graph[v][i].second;
        ll d = lower_bound(graph[u].begin(), graph[u].end(), make_pair(v, 0ll))->second;
        sum += d-c;
        dfs(u);
        sum -= d-c;
    }
}
int main(){
    int n, i, j, a, b, q, v;
    ll c, d;
    scanf("%d", &n);
    for(i=1; i<n; i++){
        scanf("%d %d %lld %lld", &a, &b, &c, &d);
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, d));
    }
    for(i=1;i <=n; i++)
        sort(graph[i].begin(), graph[i].end());
    construct_tree(1);
    mn = sum;
    memset(ch, 0, sizeof(ch));
    dfs(1);
    printf("%lld\n", mn);
    return 0;
    for(i=1; i<=n; i++)
        ans[i] = INF;
    for(i=1; i<=n; i++){
        for(j=1; j<=n; j++){
            tree[j].clear();
            ch[j] = 0;
        }
        sum = 0;
        construct_tree(i);
        ans[1] = min(ans[1], sum);
        for(j=1; j<=n; j++){
            ans[j] = min(ans[j], sum);
            for(int k=1; k<=n; k++)
                ch[k]=0;
            int v = deepest_vertex(i, 0);
            if(v>=i)
                break;
            sum -= depth[v];
            delete_edge(v, i);
        }
    }
    scanf("%d", &q);
    for(i=2; i<=n; i++){
        ans[i] = min(ans[i-1], ans[i]);
    }
    while(q--){
        scanf("%d", &v);
        printf("%lld\n", ans[v]);
    }
    return 0;
}

Compilation message

designated_cities.cpp: In function 'void construct_tree(int)':
designated_cities.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0; i<graph[v].size(); i++){
      |                  ~^~~~~~~~~~~~~~~~
designated_cities.cpp: In function 'int deepest_vertex(int, ll)':
designated_cities.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0; i<tree[v].size(); i++){
      |                  ~^~~~~~~~~~~~~~~
designated_cities.cpp: In function 'void delete_edge(int, int)':
designated_cities.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0; i<tree[p].size(); i++){
      |                      ~^~~~~~~~~~~~~~~
designated_cities.cpp: In function 'void dfs(int)':
designated_cities.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0; i<graph[v].size(); i++){
      |                  ~^~~~~~~~~~~~~~~~
designated_cities.cpp: In function 'int main()':
designated_cities.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
designated_cities.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d %d %lld %lld", &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
designated_cities.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         scanf("%d", &v);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 167 ms 33292 KB Output is correct
3 Correct 154 ms 46508 KB Output is correct
4 Correct 130 ms 31668 KB Output is correct
5 Correct 124 ms 32968 KB Output is correct
6 Correct 143 ms 34640 KB Output is correct
7 Correct 110 ms 31680 KB Output is correct
8 Correct 206 ms 46928 KB Output is correct
9 Correct 107 ms 33204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 167 ms 33292 KB Output is correct
3 Correct 154 ms 46508 KB Output is correct
4 Correct 130 ms 31668 KB Output is correct
5 Correct 124 ms 32968 KB Output is correct
6 Correct 143 ms 34640 KB Output is correct
7 Correct 110 ms 31680 KB Output is correct
8 Correct 206 ms 46928 KB Output is correct
9 Correct 107 ms 33204 KB Output is correct
10 Incorrect 3 ms 10584 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -