# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
640191 |
2022-09-13T22:11:40 Z |
sondos225 |
Network (BOI15_net) |
C++17 |
|
2 ms |
4308 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);//order_of_key()
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb emplace_back
#define pf emplace_front
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define mp make_pair
#define mt make_tuple
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define fi first
#define se second
#define la "LA"
#define pii pair<int,int>
// to use cmd ctrl+shift+c then g++ name.cpp -o name2.exe then name2 then input
//ctrl+shift+p to open search
//shift+alt+a stack comment2
///power function works in log2b
// int pwr(int a, int b)
// {
// int po = 1;
// while ( b )
// {
// if ( b & 1 )
// {
// po = po * a;
// --b;
// }
// a = a*a;
// b = b/2;
// }
// return po;
// }
int len[500001];
bool cmp (int a,int b)
{
return len[a]<len[b];
}
signed main()
{
fast
// #ifndef LOCAL
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
int n;
cin>>n;
vector <int> a[n+1];
forr(i,0,n-1)
{
int x,y;
cin>>x >>y;
a[x].pb(y);
a[y].pb(x);
}
vector <int> leaf;
forr(i,1,n+1)
{
if (a[i].sz==1)
{
leaf.pb(i);
}
}
mms(len,-1);
queue <int> q;
q.push(leaf[0]);
len[leaf[0]]=0;
while(!q.empty())
{
int w=q.front();
q.pop();
forr(i,0,a[w].sz)
{
if (len[a[w][i]]==-1)
{
len[a[w][i]]=len[w]+1;
q.push(a[w][i]);
}
}
}
int cnt=(leaf.sz/2)+(leaf.sz%2);
cout<<cnt<<nn;
sort(all(leaf),cmp);
cnt=leaf.sz;
// cout<<leaf.sz<<endl<<endl;
int i=0, j=cnt-1;
while(cnt>0)
{
// cout<<yes<<cnt<<endl;
if (cnt==1)
{
cout<<leaf[i]<<' '<<leaf[leaf.sz-1]<<nn;
}
else
{
cout<<leaf[i]<<' '<<leaf[j]<<nn;
i++;
j--;
}
cnt-=2;
}
return 0;
}
Compilation message
net.cpp: In function 'int main()':
net.cpp:22:36: 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]
22 | #define forr(i,j,n) for (int i=j; i<n; i++)
| ^
net.cpp:87:9: note: in expansion of macro 'forr'
87 | forr(i,0,a[w].sz)
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4172 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4128 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4168 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4172 KB |
Output is correct |
15 |
Correct |
2 ms |
4172 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Incorrect |
2 ms |
4172 KB |
Breaking single line is causing network to disconnect. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4172 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4128 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4168 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4172 KB |
Output is correct |
15 |
Correct |
2 ms |
4172 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Incorrect |
2 ms |
4172 KB |
Breaking single line is causing network to disconnect. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4172 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4128 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4168 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4172 KB |
Output is correct |
15 |
Correct |
2 ms |
4172 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Incorrect |
2 ms |
4172 KB |
Breaking single line is causing network to disconnect. |
19 |
Halted |
0 ms |
0 KB |
- |