Submission #940254

#TimeUsernameProblemLanguageResultExecution timeMemory
940254Zero_OPNetwork (BOI15_net)C++14
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; using int64 = int64_t; #define REP(i, n) for(int i = 0, _n = n; i < _n; ++i) #define REPD(i, n) for(int i = n - 1; i >= 0; --i) #define FOR(i, l, r) for(int i = l, _r = r; i <= _r; ++i) #define FORD(i, r, l) for(int i = r, _l = l; i >= _l; --i) #define left __left #define right __right #define prev __prev #define next __next #define div __div #define pb push_back #define pf push_front #define sz(v) (int)v.size() #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) #define debug(v) "[" #v " = " << (v) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b){ a = b; return true; } return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b){ a = b; return true; } return false; } template<int dimension, class T> struct vec : public vector<vec<dimension - 1, T>> { static_assert(dimension > 0, "Dimension must be positive !\n"); template<typename... Args> vec(int n = 0, Args... args) : vector<vec<dimension - 1, T>>(n, vec<dimension - 1, T>(args...)) {} }; template<class T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) {} }; #define Zero_OP //turn off when submitting #ifdef Zero_OP void init(void); void process(void); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define task "antuvu" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int T = 1; //cin >> T; while(T--) { init(); process(); } return 0; } const int MAX = 5e5 + 5; int n, deg[MAX]; void init(){ cin >> n; REP(i, n - 1){ int u, v; cin >> u >> v; --u, --v; ++deg[u]; ++deg[v]; } } void process(){ vector<int> leaves; REP(i, n){ if(deg[i] == 1){ leaves.pb(i); } } int res = (sz(leaves) + 1) / 2; cout << res << '\n'; REP(i, res){ cout << leaves[i] + 1 << ' ' << 1 + leaves[sz(leaves) - 1 - i] << '\n'; } } #endif

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...