Submission #397711

#TimeUsernameProblemLanguageResultExecution timeMemory
397711ly20Split the Attractions (IOI19_split)C++17
22 / 100
584 ms1048580 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 112345; bool vl = false; int resp[MAXN], sub[MAXN]; vector <int> grafo[MAXN]; int p1, p2; int N; void dfs1(int v, int p) { sub[v] = 1; for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; dfs1(viz, v); sub[v] += sub[viz]; } } void dfs2(int v, int p) { vl = true; if(p1 > 0) { p1--; resp[v] = 1; } for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; dfs2(viz, v); } } void dfs3(int v, int p) { vl = true; if(p2 > 0) { p2--; resp[v] = 2; } for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; dfs3(viz, v); } } bool dfs(int v, int p) { for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; if(sub[viz] >= p2 && sub[v] - sub[viz] >= p1) { dfs2(v, viz); dfs3(viz, v); return true; } if(sub[viz] >= p1 && sub[v] - sub[viz] >= p2) { dfs2(viz, v); dfs3(v, viz); return true; } int sp = sub[v], sf = sub[viz]; sub[viz] = sub[v]; sub[v] = sp - sf; if(dfs(viz, v)) return true; sub[viz] = sf; sub[v] = sp; } return false; } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { N = n; vector<int> res; int m = p.size(); p1 = a; p2 = b; for(int i = 0; i < m; i++) { int a1 = p[i], b1 = q[i]; grafo[a1].push_back(b1); grafo[b1].push_back(a1); } dfs1(0, 0); dfs(0, 0); for(int i = 0; i < n; i++) { if(vl && resp[i] == 0) resp[i] = 3; res.push_back(resp[i]); } return res; }

Compilation message (stderr)

split.cpp: In function 'void dfs1(int, int)':
split.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void dfs2(int, int)':
split.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void dfs3(int, int)':
split.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
split.cpp: In function 'bool dfs(int, int)':
split.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...