답안 #304553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304553 2020-09-21T13:44:07 Z Ruxandra985 Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 16376 KB
#include <bits/stdc++.h>
#define DIMN 200010
using namespace std;
int sol , x[DIMN] , propag[DIMN] ,f[DIMN];
vector <int> v[DIMN];
 
void dfs (int nod , int tt){
    int i , vecin;
    f[nod] = 0;
 
    if (v[nod].size() < 2)
        f[nod] = 1;
 
    for (i = 0 ; i < v[nod].size() ; i++){
        vecin = v[nod][i];
        if (vecin != tt){
 
            dfs(vecin , nod);
            f[nod] += f[vecin];
            if (f[vecin]  % 2 == 0)
                sol++;
        }
    }
 
}
 
 
 
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , q , xx , y , d , i;
    fscanf (fin,"%d%d",&n,&q);
    for (i = 1 ; i < n ; i++){
        fscanf (fin,"%d%d",&xx,&y);
        v[xx].push_back(y);
        v[y].push_back(xx);
    }
    for (;q;q--){
        fscanf (fin,"%d",&d);
 
        for (i = 1 ; i <= d ; i++){
            fscanf (fin,"%d",&x[i]);
        }
 
        for (i = 1 ; i <= d ; i++){
            v[x[i]].push_back(n + i);
        }
 
        sol = 0;
 
 
        for (i = 1 ; i <= n ; i++){
            if (v[i].size() > 1){
                dfs (i , 0); /// i e radacina acum
                if (f[i] % 2 == 1)
                    fprintf (fout,"-1\n");
                break;
            }
        }
        if (f[i] % 2 == 0)
            fprintf (fout,"%d\n",n + d - 1 + sol);
        for (i = 1 ; i <= d ; i++){
            v[x[i]].pop_back();
        }
 
    }
    return 0;
}

Compilation message

cleaning.cpp: In function 'void dfs(int, int)':
cleaning.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (i = 0 ; i < v[nod].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~
cleaning.cpp: In function 'int main()':
cleaning.cpp:34:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     fscanf (fin,"%d%d",&n,&q);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
cleaning.cpp:36:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         fscanf (fin,"%d%d",&xx,&y);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
cleaning.cpp:41:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         fscanf (fin,"%d",&d);
      |         ~~~~~~~^~~~~~~~~~~~~
cleaning.cpp:44:20: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |             fscanf (fin,"%d",&x[i]);
      |             ~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Execution timed out 1093 ms 5876 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6272 KB Output is correct
2 Correct 21 ms 6272 KB Output is correct
3 Correct 44 ms 9020 KB Output is correct
4 Correct 60 ms 9716 KB Output is correct
5 Correct 80 ms 11024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 6648 KB Output is correct
2 Correct 22 ms 6656 KB Output is correct
3 Correct 64 ms 14712 KB Output is correct
4 Correct 93 ms 16376 KB Output is correct
5 Correct 60 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 6392 KB Output is correct
2 Correct 167 ms 5880 KB Output is correct
3 Correct 231 ms 5760 KB Output is correct
4 Correct 276 ms 6392 KB Output is correct
5 Correct 250 ms 6392 KB Output is correct
6 Correct 292 ms 6392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 8824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Execution timed out 1093 ms 5876 KB Time limit exceeded