답안 #68216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68216 2018-08-16T08:43:23 Z top34051 동기화 (JOI13_synchronization) C++17
0 / 100
8000 ms 37848 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<pii> pos[maxn];
vector<pii> add[maxn];
int ask[maxn];
int res[maxn];

void solve(int u, int last) {
    add[u].clear();
	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) {
////            printf("\tupdate %d : %d %d\n",up,x,sum-prev);
            add[up].push_back({x,sum-prev});
            prev = sum;
		}
	}
	res[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]) {
  	    	pos[e[x].X].push_back({i,e[x].Y});
        	pos[e[x].Y].push_back({i,e[x].X});
        	open[x] = 1;
        }
        else {
  	    	pos[e[x].X].push_back({i-1,e[x].Y});
        	pos[e[x].Y].push_back({i-1,e[x].X});
            open[x] = 0;
        }
	}
	for(int i=1;i<=q;i++) {
		int x; scanf("%d",&x);
        solve(x,0);
        printf("%d\n",res[x]);
	}
}

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:41: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:43: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:49: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:62:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
          ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 17 ms 14564 KB Output is correct
3 Incorrect 17 ms 14624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 128 ms 32948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 32948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8041 ms 37848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 37848 KB Output is correct
2 Correct 16 ms 37848 KB Output is correct
3 Incorrect 16 ms 37848 KB Output isn't correct
4 Halted 0 ms 0 KB -