답안 #129953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129953 2019-07-13T15:52:00 Z Markomafko972 Regions (IOI09_regions) C++14
1 / 100
3739 ms 131076 KB
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;

int n, r, q, cv, q1, q2;
int sq;
vector<int> v[200002];
unordered_map<int, ll> m[25002];
int w[200002];
int kol[200002];
int kol2[200002];
vector<int> g[200002];
int t;
int d1[200002];
int d2[200002];

void dfs(int x) {
	for (int i = 0; i < v[x].size(); i ++) {
		int sus = v[x][i];
		dfs(sus);
		kol[x] += kol[sus];
	}
	
	//cout << "mapa od " << x << ", " << t << " += " << kol[x] << endl; 
	m[w[x]][t] += kol[x];
}

void rek(int x, int y) {
	y += kol2[x];
	m[t][w[x]] += y;
	for (int i = 0; i < v[x].size(); i ++) {
		rek(v[x][i], y);
	}
}

int tren;
void ord(int x) {
	tren ++;
	d1[x] = tren;
	for (int i = 0; i < v[x].size(); i ++) {
		ord(v[x][i]);
	}
	d2[x] = tren;
	//cout << x << ": " << d1[x] << " " << d2[x] << endl;
}

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> r >> q;
	sq = sqrt(n);
	cin >> w[1];
	g[w[1]].push_back(1);
	for (int i = 2; i <= n; i ++) {
		cin >> cv >> w[i];
		g[w[i]].push_back(i);
		v[cv].push_back(i);
	}
	
	ord(1);
	
	for (int i = 1; i <= r; i ++) {
		if (g[i].size() > sq) {
			memset(kol, 0, sizeof kol);
			memset(kol2, 0, sizeof kol2);
			t = i;
			for (int j = 0; j < g[i].size(); j ++) {
				kol[g[i][j]] = 1;
				kol2[g[i][j]] = 1;
			}
			
			dfs(1);
			rek(1, 0);
		}
	}
	
	for (int i = 0; i < q; i ++) {
		cin >> q1 >> q2;
		if (g[q1].size() > sq && g[q2].size() > sq) {
			m[q1][q2] /= 2;
		}
		
		if (g[q1].size() <= sq && g[q2].size() <= sq && m[q1][q2] == 0) {

			if (m[q1][q2] == 0) m[q1][q2] = -1;
		}
		
		cout << max(0LL, m[q1][q2]) << endl;
	}

	return 0;
}

Compilation message

regions.cpp: In function 'void dfs(int)':
regions.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[x].size(); i ++) {
                  ~~^~~~~~~~~~~~~
regions.cpp: In function 'void rek(int, int)':
regions.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[x].size(); i ++) {
                  ~~^~~~~~~~~~~~~
regions.cpp: In function 'void ord(int)':
regions.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[x].size(); i ++) {
                  ~~^~~~~~~~~~~~~
regions.cpp: In function 'int main()':
regions.cpp:69:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (g[i].size() > sq) {
       ~~~~~~~~~~~~^~~~
regions.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < g[i].size(); j ++) {
                    ~~^~~~~~~~~~~~~
regions.cpp:85:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (g[q1].size() > sq && g[q2].size() > sq) {
       ~~~~~~~~~~~~~^~~~
regions.cpp:85:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (g[q1].size() > sq && g[q2].size() > sq) {
                            ~~~~~~~~~~~~~^~~~
regions.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (g[q1].size() <= sq && g[q2].size() <= sq && m[q1][q2] == 0) {
       ~~~~~~~~~~~~~^~~~~
regions.cpp:89:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (g[q1].size() <= sq && g[q2].size() <= sq && m[q1][q2] == 0) {
                             ~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12664 KB Output is correct
2 Incorrect 12 ms 11128 KB Output isn't correct
3 Incorrect 13 ms 11128 KB Output isn't correct
4 Incorrect 17 ms 11132 KB Output isn't correct
5 Incorrect 16 ms 11148 KB Output isn't correct
6 Incorrect 33 ms 11256 KB Output isn't correct
7 Incorrect 28 ms 11448 KB Output isn't correct
8 Incorrect 42 ms 11256 KB Output isn't correct
9 Incorrect 41 ms 11700 KB Output isn't correct
10 Incorrect 100 ms 11896 KB Output isn't correct
11 Incorrect 109 ms 12152 KB Output isn't correct
12 Incorrect 103 ms 12744 KB Output isn't correct
13 Incorrect 169 ms 12444 KB Output isn't correct
14 Incorrect 182 ms 14544 KB Output isn't correct
15 Incorrect 205 ms 17092 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1038 ms 18172 KB Output isn't correct
2 Incorrect 1010 ms 16896 KB Output isn't correct
3 Incorrect 1308 ms 21488 KB Output isn't correct
4 Incorrect 290 ms 13592 KB Output isn't correct
5 Incorrect 303 ms 15316 KB Output isn't correct
6 Incorrect 1625 ms 45944 KB Output isn't correct
7 Incorrect 2139 ms 59500 KB Output isn't correct
8 Incorrect 3296 ms 107332 KB Output isn't correct
9 Incorrect 1577 ms 24768 KB Output isn't correct
10 Runtime error 2650 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Incorrect 1992 ms 28056 KB Output isn't correct
12 Incorrect 1200 ms 26572 KB Output isn't correct
13 Incorrect 1201 ms 28080 KB Output isn't correct
14 Incorrect 3739 ms 58076 KB Output isn't correct
15 Incorrect 2196 ms 35716 KB Output isn't correct
16 Incorrect 2399 ms 40692 KB Output isn't correct
17 Incorrect 3446 ms 69920 KB Output isn't correct