제출 #410552

#제출 시각아이디문제언어결과실행 시간메모리
410552Richw818Traffic (IOI10_traffic)C++17
컴파일 에러
0 ms0 KiB
/* * Written by: Richw818 * Lang: C++17 * main.cpp */ #include <bits/stdc++.h> using namespace std; //Macros #define ll long long #define ull unsigned long long #define uint unsigned int #define pb push_back #define pf push_front #define eb emplace_back #define ef emplace_front #define str string #define fi first #define se second #define REP(i, n) for(int i = 0; i < (int)n; ++i) #define sz(a) (int)(a.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() //IO template<class H, class T> void read(pair<H, T> &p); template<class T> void read(vector<T>& v); template<class T> void read(T& t){ cin >> t; } template<class H, class... T> void read(H& h, T&... t){ read(h); read(t...); } template<class T> void read(vector<T>& v){ for(auto &t : v) read(t); } template<class H, class T> void read(pair<H, T> &p){ read(p.fi, p.se); } void setIn(str s){ freopen(s.c_str(), "r", stdin); } void setOut(str s){ freopen(s.c_str(), "w", stdout); } void setIO(str s = ""){ if(!sz(s)) return; setIn(s+".in"); setOut(s+".out"); } //Debug void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} template<class H, class... T> void dbg(H& h, T&... t){ dbg(h); dbg(t...); } #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x); #else #define dbg(x...) #endif //Constants ll MODS[2] = {1000000007, 998244353}; const ll MOD = MODS[0]; const ll INF = (ll)1e18; const double PI = acos(-1.0); const int MAXN = (int)1e6+7; //Code vector<int> pop; vector<int> tree[MAXN]; int cong[MAXN]; bitset<MAXN> vis; int traff = INT_MAX, city = -1; void dfs1(int n){ vis[n] = true; cong[n] += pop[n]; for(int adj : tree[n]){ if(!vis[adj]){ dfs1(adj); cong[n] += cong[adj]; } } } void dfs2(int n, int x){ vis[n] = true; int curr = x; for(int adj : tree[n]){ if(!vis[adj]){ dfs2(adj, x + cong[n] - cong[adj]); curr = max(curr, cong[adj]); } } if(curr < traff){ traff = curr; city = n; } } void solve(){ int n; read(n); pop.resize(n); read(pop); REP(i, n-1){ int s, d; read(s, d); tree[s].eb(d); tree[d].eb(s); } dfs1(0); vis.reset(); dfs2(0, 0); cout << city; } int main(){ setIO(); ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

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

traffic.cpp: In function 'void setIn(std::string)':
traffic.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen(s.c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
traffic.cpp: In function 'void setOut(std::string)':
traffic.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     freopen(s.c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccNEtKJH.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccx9bNEI.o:traffic.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccNEtKJH.o: in function `main':
grader.cpp:(.text.startup+0xe1): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status