Submission #68227

# Submission time Handle Problem Language Result Execution time Memory
68227 2018-08-16T09:11:22 Z top34051 Synchronization (JOI13_synchronization) C++17
0 / 100
138 ms 32044 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<pii> way[maxn];
int open[maxn];
vector<pii> edge[maxn];
int res;

int get(int x, int val) {
    int l = 0, r = edge[x].size(), mid, pos = -1;
    while(l<=r) {
        mid = (l+r)/2;
        if(edge[x][mid].X <= val) {
            pos = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    if(pos==-1) return 0;
    return min(val, edge[x][pos].Y);
}

void solve(int u, int last, int cur) {
    if(cur==0) return ;
//    printf("solve %d : %d\n",u,cur);
    res++;
	for(auto t : way[u]) {
        int v = t.X, id = t.Y;
		if(v==last) continue;
		solve(v,u,get(id,cur));
	}
}

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,i});
		way[v].push_back({u,i});
	}
	for(int i=1;i<=m;i++) {
		int x; scanf("%d",&x);
		if(!open[x]) open[x] = i;
        else {
            edge[x].push_back({open[x],i-1});
            open[x] = 0;
        }
	}
	for(int x=1;x<n;x++) {
        if(open[x]) {
            edge[x].push_back({open[x],m});
        }
	}
	for(int i=1;i<=q;i++) {
		int x; scanf("%d",&x);
		res = 0;
        solve(x,0,m);
        printf("%d\n",res);
	}
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:42: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:44: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);
          ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 17264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 17264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 138 ms 32044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 32044 KB Output isn't correct
2 Halted 0 ms 0 KB -