제출 #764946

#제출 시각아이디문제언어결과실행 시간메모리
764946vjudge1Network (BOI15_net)C++17
0 / 100
3 ms4948 KiB
/****************** tree-bends-in-youth //22///06///2023/// ******************/ #include <bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() using namespace std; const ll N = 2e5 + 1; const ll INF = 1e17; const ll MOD = 1e9 + 7; vector <ll> g[N]; map <ll,ll> used; ll d[N]; void solve(){ ll n; cin >> n; set <ll> s; for(ll i = 1;i <= n;i++){ s.insert(i); } for(ll i = 1;i < n;i++){ ll x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); if(g[x].size() > 1)s.erase(x); if(g[y].size() > 1)s.erase(y); } vector <ll> a; for(auto to : s){ a.pb(to); } cout << ((a.size() + 1) / 2) << '\n'; for(ll i = 0;i < a.size();i++){ if(s.count(a[i]) == 0)continue; s.erase(a[i]); cout << a[i] << " "; if(s.empty()){ cout << a[i- 1] << '\n'; continue; } for(ll j = 1;j <= n;j++){ d[j] = 0; } queue <ll> q; q.push(a[i]); used.clear(); used[a[i]] = 1; while(!q.empty()){ ll v= q.front(); q.pop(); for(auto to : g[v]){ if(used[to] == 0){ q.push(to); used[to] = 1; d[to] = d[v] + 1; } } } ll mx = 0,w = 0; for(auto to : s){ if(d[to] > mx){ mx = d[to]; w = to; } } cout << w << "\n"; s.erase(w); } } main () { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("censor.in","r",stdin); //freopen("censor.out","w",stdout); ll T = 1; //cin >> T; for(ll i = 1;i <= T;i++){ // cout << "Case " << i << ":\n"; solve(); } }

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

net.cpp: In function 'void solve()':
net.cpp:38:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(ll i = 0;i < a.size();i++){
      |                  ~~^~~~~~~~~~
net.cpp: At global scope:
net.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...