#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,q,tot,res;
int x[200005],y[200005],h[100005],nxt[400005],v[400005],d[100005],du[100005];
bool rem[100005],edg[400005];
void addedge(int x,int y){
v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
v[++tot]=x; nxt[tot]=h[y]; h[y]=tot;
}
void bfs(){
for(int i=1;i<=n;i++) d[i]=-1;
d[1]=0;
queue<int> que;
que.push(1);
while(!que.empty()){
int x=que.front();
que.pop();
for(int p=h[x];p;p=nxt[p]){
if(d[v[p]]==-1){
d[v[p]]=d[x]+1;
que.push(v[p]);
}
}
}
}
void work(int x){
if(x==1||rem[x]) return;
res++;
rem[x]=true;
for(int p=h[x];p;p=nxt[p]){
if(d[v[p]]>d[x]&&!edg[p]){
edg[p]=true;
du[v[p]]--;
if(du[v[p]]==0) work(v[p]);
}
}
}
int main(){
n=readint();
m=readint();
q=readint();
for(int i=1;i<=m;i++){
x[i]=readint();
y[i]=readint();
addedge(x[i],y[i]);
}
bfs();
map<pii,int> idx;
for(int i=1;i<=n;i++){
for(int p=h[i];p;p=nxt[p]){
idx[mp(i,v[p])]=p;
}
}
for(int i=1;i<=n;i++){
for(int p=h[i];p;p=nxt[p]){
if(d[v[p]]<d[i]) du[i]++;
}
}
for(int i=2;i<=n;i++) if(du[i]==0) work(i);
while(q--){
int i=readint();
if(d[x[i]]==d[y[i]]){
printf("%d\n",res);
continue;
}
if(d[x[i]]>d[y[i]]) swap(x[i],y[i]);
if(rem[x[i]]){
printf("%d\n",res);
continue;
}
edg[idx[mp(x[i],y[i])]]=true;
du[y[i]]--;
if(du[y[i]]==0) work(y[i]);
printf("%d\n",res);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
87 ms |
33876 KB |
Output is correct |
10 |
Correct |
79 ms |
33972 KB |
Output is correct |
11 |
Correct |
85 ms |
33824 KB |
Output is correct |
12 |
Correct |
90 ms |
33976 KB |
Output is correct |
13 |
Correct |
74 ms |
33876 KB |
Output is correct |
14 |
Correct |
71 ms |
33560 KB |
Output is correct |
15 |
Correct |
48 ms |
27220 KB |
Output is correct |
16 |
Correct |
43 ms |
20552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
34128 KB |
Output is correct |
2 |
Correct |
78 ms |
33940 KB |
Output is correct |
3 |
Correct |
82 ms |
26996 KB |
Output is correct |
4 |
Correct |
82 ms |
33952 KB |
Output is correct |
5 |
Correct |
70 ms |
33568 KB |
Output is correct |
6 |
Correct |
74 ms |
33364 KB |
Output is correct |
7 |
Correct |
32 ms |
20564 KB |
Output is correct |
8 |
Correct |
44 ms |
20308 KB |
Output is correct |
9 |
Correct |
40 ms |
18116 KB |
Output is correct |
10 |
Correct |
41 ms |
17848 KB |
Output is correct |
11 |
Correct |
134 ms |
33136 KB |
Output is correct |
12 |
Correct |
110 ms |
32340 KB |
Output is correct |
13 |
Correct |
106 ms |
31604 KB |
Output is correct |
14 |
Correct |
120 ms |
34500 KB |
Output is correct |
15 |
Correct |
114 ms |
31312 KB |
Output is correct |
16 |
Correct |
109 ms |
30544 KB |
Output is correct |
17 |
Correct |
84 ms |
33604 KB |
Output is correct |
18 |
Correct |
68 ms |
27824 KB |
Output is correct |
19 |
Correct |
119 ms |
36412 KB |
Output is correct |
20 |
Correct |
88 ms |
34128 KB |
Output is correct |
21 |
Correct |
53 ms |
24144 KB |
Output is correct |
22 |
Correct |
52 ms |
23892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
87 ms |
33876 KB |
Output is correct |
10 |
Correct |
79 ms |
33972 KB |
Output is correct |
11 |
Correct |
85 ms |
33824 KB |
Output is correct |
12 |
Correct |
90 ms |
33976 KB |
Output is correct |
13 |
Correct |
74 ms |
33876 KB |
Output is correct |
14 |
Correct |
71 ms |
33560 KB |
Output is correct |
15 |
Correct |
48 ms |
27220 KB |
Output is correct |
16 |
Correct |
43 ms |
20552 KB |
Output is correct |
17 |
Correct |
75 ms |
34128 KB |
Output is correct |
18 |
Correct |
78 ms |
33940 KB |
Output is correct |
19 |
Correct |
82 ms |
26996 KB |
Output is correct |
20 |
Correct |
82 ms |
33952 KB |
Output is correct |
21 |
Correct |
70 ms |
33568 KB |
Output is correct |
22 |
Correct |
74 ms |
33364 KB |
Output is correct |
23 |
Correct |
32 ms |
20564 KB |
Output is correct |
24 |
Correct |
44 ms |
20308 KB |
Output is correct |
25 |
Correct |
40 ms |
18116 KB |
Output is correct |
26 |
Correct |
41 ms |
17848 KB |
Output is correct |
27 |
Correct |
134 ms |
33136 KB |
Output is correct |
28 |
Correct |
110 ms |
32340 KB |
Output is correct |
29 |
Correct |
106 ms |
31604 KB |
Output is correct |
30 |
Correct |
120 ms |
34500 KB |
Output is correct |
31 |
Correct |
114 ms |
31312 KB |
Output is correct |
32 |
Correct |
109 ms |
30544 KB |
Output is correct |
33 |
Correct |
84 ms |
33604 KB |
Output is correct |
34 |
Correct |
68 ms |
27824 KB |
Output is correct |
35 |
Correct |
119 ms |
36412 KB |
Output is correct |
36 |
Correct |
88 ms |
34128 KB |
Output is correct |
37 |
Correct |
53 ms |
24144 KB |
Output is correct |
38 |
Correct |
52 ms |
23892 KB |
Output is correct |
39 |
Correct |
136 ms |
36392 KB |
Output is correct |
40 |
Correct |
151 ms |
36524 KB |
Output is correct |
41 |
Correct |
109 ms |
28488 KB |
Output is correct |
42 |
Correct |
120 ms |
36712 KB |
Output is correct |
43 |
Correct |
132 ms |
36556 KB |
Output is correct |
44 |
Correct |
131 ms |
35924 KB |
Output is correct |
45 |
Correct |
123 ms |
35876 KB |
Output is correct |
46 |
Correct |
54 ms |
26116 KB |
Output is correct |
47 |
Correct |
62 ms |
21840 KB |
Output is correct |
48 |
Correct |
71 ms |
21588 KB |
Output is correct |
49 |
Correct |
80 ms |
19164 KB |
Output is correct |
50 |
Correct |
72 ms |
19044 KB |
Output is correct |
51 |
Correct |
68 ms |
20308 KB |
Output is correct |
52 |
Correct |
82 ms |
20088 KB |
Output is correct |
53 |
Correct |
66 ms |
19024 KB |
Output is correct |
54 |
Correct |
103 ms |
19092 KB |
Output is correct |