Submission #994590

#TimeUsernameProblemLanguageResultExecution timeMemory
994590guagua0407Network (BOI15_net)C++17
100 / 100
373 ms47396 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=5e5+5; vector<int> adj[mxn]; int deg[mxn]; vector<int> vec; void dfs(int v,int p=-1){ for(auto u:adj[v]){ if(u==p) continue; deg[v]++; deg[u]++; dfs(u,v); } if(deg[v]==1) vec.push_back(v); } int main() {_ int n; cin>>n; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } dfs(1); int ans=((int)vec.size()+1)/2; cout<<ans<<'\n'; for(int i=0;i<ans;i++){ cout<<vec[i]<<' '<<vec[(i+(int)vec.size()/2)]<<'\n'; } return 0; } //maybe its multiset not set //yeeorz //laborz

Compilation message (stderr)

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