Submission #368432

# Submission time Handle Problem Language Result Execution time Memory
368432 2021-02-20T04:21:10 Z 1306439119 Traffic (IOI10_traffic) C++11
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pi pair<int, int>
#define endl '\n'
#define f first
#define s second

void setIO(string name = "") { 
    ios_base::sync_with_stdio(0); 
	cin.tie(0);     
    if (name.length()) {
        freopen((name+".in").c_str(), "r", stdin); 
        freopen((name+".out").c_str(), "w", stdout);
    }
}

struct node{
    int id, person;
    vector<node*> adj;
    node(int i, int p, vector<node*> a){
        id = i;
        person = p;
        adj = a;
    }
};

int n;
node* A[1000000];

ll dfs(node* curr, int prev){
    ll sum = curr->person;
    for(node* next : curr->adj){
        if(prev != next->id){
            sum += dfs(next, curr->id);
        }
    }
    return sum;
}

ll root(node* root){    
    ll ret = 0;
    for(node* next : root->adj){
        ret = max(ret, dfs(next, root->id));
    }
    return ret;
}

int LocateCentre(int n, int* p, int* s, int* d){
    for(int i = 0; i < n; i++){        
        A[i] = new node(i, p[i], vector<node*>());
    }
    for(int i = 0; i < n-1; i++){        
        A[s[i]]->adj.push_back(A[d[i]]);
        A[d[i]]->adj.push_back(A[s[i]]);
    }
    ll res = LLONG_MAX;
    for(int i = 0; i < n; i++){
        res = min(res, root(A[i]));
    }

    return res;
}

/*int main(){			 
    setIO("");               
    
    return 0;
}*/

Compilation message

traffic.cpp: In function 'void setIO(std::string)':
traffic.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
traffic.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -