제출 #368490

#제출 시각아이디문제언어결과실행 시간메모리
3684901306439119Traffic (IOI10_traffic)C++11
50 / 100
1553 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int, int> #define endl '\n' 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]; map<pi, int> memo; ll dfs(node* curr, int prev){ if(memo.find({prev, curr->id}) != memo.end()){ return memo[{prev, curr->id}]; } ll sum = curr->person; for(node* next : curr->adj){ if(prev != next->id){ sum += dfs(next, curr->id); } } memo[{prev, curr->id}] = sum; 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, ret = -1; for(int i = 0; i < n; i++){ ll curr = root(A[i]); if(curr < res){ res = curr; ret = A[i]->id; } } return ret; } /*int main(){ setIO(""); int* p = new int[5]; int* s = new int[4]; int* d = new int[4]; p[0] = 10, p[1] = 10, p[2] = 10, p[3] = 20, p[4] = 20; s[0] = 0, s[1] = 1, s[2] = 2, s[3] = 3; d[0] = 2, d[1] = 2, d[2] = 3, d[3] = 4; cout << LocateCentre(5, p, s, d) << endl;; return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

traffic.cpp: In function 'void setIO(std::string)':
traffic.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
traffic.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...