답안 #68160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68160 2018-08-16T07:20:22 Z top34051 동기화 (JOI13_synchronization) C++17
0 / 100
209 ms 41148 KB
//subtask 1
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define X first
#define Y second
const int maxn = 2e5 + 5;

int n,m,q;
vector<int> way[maxn];
pii e[maxn];
int open[maxn];
vector<int> pos[maxn];
vector<pii> add[maxn];
int ask[maxn];
int res[maxn];

void solve(int u, int last) {
	for(auto v : way[u]) {
		if(v==last) continue;
		solve(v,u);
	}
	sort(pos[u].begin(),pos[u].end());
	pos[u].erase(unique(pos[u].begin(),pos[u].end()),pos[u].end());
	sort(add[u].begin(),add[u].end());
	int i = 0, sum = 1, prev = 0;
	for(auto x : pos[u]) {
		while(i<add[u].size() && add[u][i].X <= x) sum += add[u][i++].Y;
//		printf("%d : pos = %d : sum = %d\n",u,x,sum);
		add[last].push_back({x,sum-prev});
		prev = sum;
	}
	res[ask[u]] = sum;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<n;i++) {
		int u,v; scanf("%d%d",&u,&v);
		way[u].push_back(v);
		way[v].push_back(u);
		e[i] = {u,v};
	}
	for(int i=1;i<=m;i++) {
		int x; scanf("%d",&x);
		if(!open[x]) {
			open[x] = 1;
			pos[e[x].X].push_back(i);
			pos[e[x].Y].push_back(i);
		}
		else open[x] = 0;
	}
	int root;
	for(int i=1;i<=q;i++) {
		int x; scanf("%d",&x);
		ask[x] = i;
		root = x;
	}
	solve(root,0);
	for(int i=1;i<=q;i++) printf("%d\n",res[i]);
}

Compilation message

synchronization.cpp: In function 'void solve(int, int)':
synchronization.cpp:29:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(i<add[u].size() && add[u][i].X <= x) sum += add[u][i++].Y;
         ~^~~~~~~~~~~~~~
synchronization.cpp: In function 'int main()':
synchronization.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~
synchronization.cpp:40:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u,v; scanf("%d%d",&u,&v);
            ~~~~~^~~~~~~~~~~~~~
synchronization.cpp:46:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
          ~~~~~^~~~~~~~~
synchronization.cpp:56:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
          ~~~~~^~~~~~~~~
synchronization.cpp:60:7: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
  solve(root,0);
  ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 14456 KB Output is correct
2 Incorrect 16 ms 14576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 32908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 32908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 209 ms 41148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 41148 KB Output isn't correct
2 Halted 0 ms 0 KB -