이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define INF 0x7fffffff
using namespace std;
vector<int>cg[300005],cn[300005];
int n,m,p,ed[300005][2],cur,flag,vis[300005],cnt;
int dist1[300005],dist2[300005],cyc_len[2];
bool state,in_cyc[2];
struct destination {
int dist[300005],cyc_len=0;
bool in_cyc=false;
}d[2];
void find_cyc(int idx) {
if(vis[idx]==1) {
if(!d[state].in_cyc && idx!=cn[p][state]) return;
d[state].in_cyc=true;
d[state].cyc_len++;
}
if(vis[idx]==2) return;
vis[idx]++;
find_cyc(cn[ed[idx][1]][(cg[ed[idx][1]][0]==ed[idx][0] && cg[ed[idx][1]].size()>1)?1:0]);
vis[idx]=0;
}
int find_dist(int idx) {
if(cn[p][state]==idx) return d[state].dist[idx]=0;
if(vis[idx]) return d[state].dist[idx];
vis[idx]++;
return d[state].dist[idx]=find_dist(cn[ed[idx][1]][(cg[ed[idx][1]][0]==ed[idx][0] && cg[ed[idx][1]].size()>1)?1:0])+1;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
int i,j,k,tmp; n=N; m=M; p=P;
for(i=0;i<m;i++) {
ed[i][0]=R[i][0];
ed[i][1]=R[i][1];
ed[i+m][0]=R[i][1];
ed[i+m][1]=R[i][0];
cg[ed[i][0]].push_back(ed[i][1]);
cn[ed[i][0]].push_back(i);
cg[ed[i][1]].push_back(ed[i][0]);
cn[ed[i][1]].push_back(i+m);
d[0].dist[i]=-INF;
d[1].dist[i]=-INF;
d[0].dist[i+M]=-INF;
d[1].dist[i+M]=-INF;
}
state=0;
find_cyc(cn[p][0]);
state=1;
find_cyc(cn[p][1]);
state=0;
for(i=0;i<2*m;i++) {
if(vis[i])continue;
find_dist(i);
}
state=1;
memset(vis,0,sizeof(vis));
for(i=0;i<2*m;i++) {
if(vis[i])continue;
find_dist(i);
}
for(i=0;i<2;i++) {
cyc_len[i]=d[i].cyc_len;
in_cyc[i]=d[i].in_cyc;
}
for(j=0;j<2*m;j++) {
dist1[j]=d[0].dist[j];
dist2[j]=d[1].dist[j];
}
for(i=0;i<Q;i++) {
cnt=0;
for(j=0;j<n;j++) {
tmp=cn[j][0];
if(dist1[tmp]>=0) {
if(dist1[tmp]==G[i]){
cnt++; continue;
}
if(dist1[tmp]<G[i] && in_cyc[0] && (G[i]-dist1[tmp])%cyc_len[0]==0) {
cnt++; continue;
}
}
if(dist2[tmp]>=0) {
if(dist2[tmp]==G[i]){
cnt++; continue;
}
if(dist2[tmp]<G[i] && in_cyc[1] && (G[i]-dist2[tmp])%cyc_len[1]==0) {
cnt++; continue;
}
}
}
answer(cnt);
}
}
컴파일 시 표준 에러 (stderr) 메시지
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:37:13: warning: unused variable 'k' [-Wunused-variable]
int i,j,k,tmp; n=N; m=M; p=P;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |