답안 #203264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203264 2020-02-20T00:56:04 Z Rakhmand Designated Cities (JOI19_designated_cities) C++14
7 / 100
314 ms 28408 KB
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 1e6 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

void istxt(bool yes){
    if(yes == 1){
        freopen("balancing.in", "r", stdin);
        //freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/e.txt", "w", stdout);
    }else{
        freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
    }
}

int n, q;
llong sum, ans, roads;
vector<pair<int, int> > g[MXN];

void dfs(int v, int p){
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i].F, cost = g[v][i].S;
        if(to == p) {
            roads += cost;
            continue;
        }
        dfs(to, v);
    }
}

void dfs2(int v, int p){
    int cost;
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i].F;
        if(to == p){
            cost = g[v][i].S;
            continue;
        }
    }
    roads -= cost;
    ans = max(ans, roads);
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i].F;
        if(to == p){
            continue;
        }
        roads += g[v][i].S;
        dfs2(to, v);
        roads -= g[v][i].S;
    }
    roads += cost;
}

int main () {
    ios;
    //istxt(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        g[u].pb({v, a});
        g[v].pb({u, b});
        sum += a + b;
    }
    dfs(1, 0);
    ans = roads;
    dfs2(1, 0);
    cin >> q;
    while(q--){
        int x;
        cin >> x;
        assert(x == 1);
        cout << sum - ans << nl;
    }
    return 0;
}

Compilation message

designated_cities.cpp: In function 'void dfs(int, int)':
designated_cities.cpp:67:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < g[v].size(); i++){
                    ~~^~~~~~~~~~~~~
designated_cities.cpp: In function 'void dfs2(int, int)':
designated_cities.cpp:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < g[v].size(); i++){
                    ~~^~~~~~~~~~~~~
designated_cities.cpp:88:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < g[v].size(); i++){
                    ~~^~~~~~~~~~~~~
designated_cities.cpp: In function 'void istxt(bool)':
designated_cities.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("balancing.in", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp: In function 'void dfs2(int, int)':
designated_cities.cpp:86:11: warning: 'cost' may be used uninitialized in this function [-Wmaybe-uninitialized]
     roads -= cost;
     ~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4988 KB Output is correct
2 Correct 251 ms 12512 KB Output is correct
3 Correct 314 ms 27872 KB Output is correct
4 Correct 246 ms 17272 KB Output is correct
5 Correct 253 ms 18672 KB Output is correct
6 Correct 266 ms 20088 KB Output is correct
7 Correct 224 ms 18800 KB Output is correct
8 Correct 303 ms 28408 KB Output is correct
9 Correct 173 ms 19304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4988 KB Output is correct
2 Correct 251 ms 12512 KB Output is correct
3 Correct 314 ms 27872 KB Output is correct
4 Correct 246 ms 17272 KB Output is correct
5 Correct 253 ms 18672 KB Output is correct
6 Correct 266 ms 20088 KB Output is correct
7 Correct 224 ms 18800 KB Output is correct
8 Correct 303 ms 28408 KB Output is correct
9 Correct 173 ms 19304 KB Output is correct
10 Runtime error 14 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -