제출 #51032

#제출 시각아이디문제언어결과실행 시간메모리
51032SpaimaCarpatilorNetwork (BOI15_net)C++17
100 / 100
687 ms153292 KiB
#include<cstdio>
#include<vector>

using namespace std;

int N, nr, rad, cod[500009];
vector < int > v[500009];

void dfs (int nod, int tata)
{
    if (v[nod].size () == 1) cod[++nr] = nod;
    for (vector < int > :: iterator it = v[nod].begin (); it != v[nod].end (); it ++)
        if (*it != tata)
            dfs (*it, nod);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y), v[y].push_back (x);
}

for (int i=1; i<=N; i++)
    if (v[i].size () >= 2) rad = i;
dfs (rad, -1);

printf ("%d\n", nr / 2 + nr % 2);
for (int i=1; i + nr / 2 <= nr; i++)
    printf ("%d %d\n", cod[i], cod[i + nr / 2]);

return 0;
}

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

net.cpp: In function 'int main()':
net.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d", &N);
 ~~~~~~^~~~~~~~~~
net.cpp:26:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &x, &y);
     ~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...