# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
765204 |
2023-06-24T09:21:09 Z |
vjudge1 |
Network (BOI15_net) |
C++17 |
|
14 ms |
23808 KB |
// Problem: C - Интернет связь
// Contest: Virtual Judge - IOI contest div-B
// URL: https://vjudge.net/contest/564767#problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) (v).begin(),(v).end()
#define rall(v) ((v).rbegin()), ((v).rend())
#define out(v) for(auto& i : v) cout << i << ' ';
#define F first
#define S second
// #define int long long
const ll N = 1e6 + 17;
const ll MOD = 1e9 + 7;
const string alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector <int > g[N];
int cnt = 1;
void solve (){
int n;
cin >>n;
for(int i = 1; i <= n - 1; i ++){
int x , y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
vector <int > ans;
for(int i = 1; i <= n; i ++){
if (g[i].size() == 1){
ans.pb(i);
}
}
cout <<(ans.size() + 1) / 2 << endl;
for(int i = 0; i < ans.size(); i += 2){
if (i + 1 == ans.size()){
cout <<ans[i] << " " << ans[i - 1] << endl;
}
else {
cout <<ans[i] << " " << ans[i + 1] << endl;
}
}
}
signed main(){
// freopen("ones.in" , "r" , stdin) ;
// freopen("ones.out" , "w" , stdout) ;
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// int cs = 1;
// cin >>T;
while (T --){
// cout <<"Case " << cs ++<< ":" << endl;
solve ();
// cout <<endl;
}
}
Compilation message
net.cpp: In function 'void solve()':
net.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < ans.size(); i += 2){
| ~~^~~~~~~~~~~~
net.cpp:46:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (i + 1 == ans.size()){
| ~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23720 KB |
Output is correct |
5 |
Correct |
14 ms |
23692 KB |
Output is correct |
6 |
Correct |
12 ms |
23748 KB |
Output is correct |
7 |
Correct |
11 ms |
23808 KB |
Output is correct |
8 |
Correct |
11 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23720 KB |
Output is correct |
5 |
Correct |
14 ms |
23692 KB |
Output is correct |
6 |
Correct |
12 ms |
23748 KB |
Output is correct |
7 |
Correct |
11 ms |
23808 KB |
Output is correct |
8 |
Correct |
11 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23720 KB |
Output is correct |
5 |
Correct |
14 ms |
23692 KB |
Output is correct |
6 |
Correct |
12 ms |
23748 KB |
Output is correct |
7 |
Correct |
11 ms |
23808 KB |
Output is correct |
8 |
Correct |
11 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |