제출 #606815

#제출 시각아이디문제언어결과실행 시간메모리
606815ThMinh_Network (BOI15_net)C++14
100 / 100
672 ms239644 KiB
#include<bits/stdc++.h> #define forin(i,a,b) for(int i=a;i<=b;++i) #define forv(a,b) for(auto &a:b) #define ii pair<int, int> using namespace std; const int N = 5e5+10; int n, root; int color[N]; vector<int> adj[N]; vector<ii> ans; queue<int> dfs(int u) { color[u] = 1; queue<int> res; if(adj[u].size() == 1) {res.push(u); return res;} forv(v, adj[u]) if(!color[v]) { queue<int> q = dfs(v); if(res.size() + q.size() > 2 && res.size() > 0 && q.size() > 0) { ans.push_back({res.front(), q.front()}); res.pop(); q.pop(); } while(!q.empty()) {res.push(q.front()); q.pop();} } return res; } int main () { cin.tie(0)->sync_with_stdio(0); if(fopen("Task.inp","r")) { freopen("Task.inp","r",stdin); freopen("WA.out","w",stdout); } cin>>n; forin(i,1,n - 1) { int u, v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } queue<int> slt; forin(i,1,n) if(adj[i].size() > 1) {slt = dfs(i); root = i; break;} if(slt.size() == 2) {root = slt.front(); slt.pop();} if(slt.size() == 1) ans.push_back({root, slt.front()}); cout<<ans.size()<<"\n"; forv(v, ans) cout<<v.first<<" "<<v.second<<"\n"; }

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

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