답안 #304552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304552 2020-09-21T13:43:12 Z Ruxandra985 Spring cleaning (CEOI20_cleaning) C++14
16 / 100
1000 ms 25976 KB
#include <bits/stdc++.h>
#define DIMN 100010
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 2 ms 2688 KB Output is correct
2 Execution timed out 1090 ms 4088 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4224 KB Output is correct
2 Correct 19 ms 4352 KB Output is correct
3 Runtime error 48 ms 14192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 4736 KB Output is correct
2 Correct 22 ms 4736 KB Output is correct
3 Runtime error 85 ms 25976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 4856 KB Output is correct
2 Correct 168 ms 3960 KB Output is correct
3 Correct 231 ms 3584 KB Output is correct
4 Correct 273 ms 4096 KB Output is correct
5 Correct 249 ms 4224 KB Output is correct
6 Correct 284 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1055 ms 5880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 7692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1090 ms 4088 KB Time limit exceeded