답안 #68186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68186 2018-08-16T07:53:52 Z top34051 동기화 (JOI13_synchronization) C++17
0 / 100
257 ms 37960 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];
vector<pii> 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(add[u].begin(),add[u].end());
	int i = 0, sum = 1, prev = 0;
	for(auto t : pos[u]) {
        int x = t.X, up = t.Y;
		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);
		if(up==last) {
            add[up].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);
        pos[e[x].X].push_back({i,e[x].Y});
        pos[e[x].Y].push_back({i,e[x].X});
	}
	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:27: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:52: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:7: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
  solve(root,0);
  ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Incorrect 15 ms 14472 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 106 ms 32116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 32116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 257 ms 37960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 37960 KB Output isn't correct
2 Halted 0 ms 0 KB -