提交记录 3808


用户 题目 状态 得分 用时 内存 语言 代码长度
wsndy noi18a. 【NOI2018】归程 Runtime Error 20 1.065 s 588320 KB C++ 2.47 KB
提交时间 评测时间
2018-07-18 18:02:38 2020-07-31 21:45:00
#include<cstdio> 
#include<cstring> 
#include<algorithm> 
using namespace std; 
inline int read() { 
	int x = 0,f = 1; 
	char c = getchar(); 
	while(c < '0' ||c > '9'){if(c == '-') f = -1;c = getchar();}  
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
} 
const int maxn = 600007; 
int n,m; 

struct node { 
	int u,v,l,a,next; 
} edge[maxn << 1]; 
int head[maxn],num = 0; 
int A[maxn],k,s; 
inline void add_edge(int u,int v,int l,int a) { edge[++ num].v = v;edge[num].next = head[u],head[u] = num; edge[num].l = l; edge[num].a = a; } 
int q[(maxn * 10)],dis[maxn]; bool vis[maxn]; 
int lastans = 0; 
int spfa(int x) { 
	int l = 0,r = 0;  
	memset(vis,0,sizeof vis); 
	memset(dis,0x3f,sizeof dis); 
	q[++ r] = x; vis[x] = 1; dis[x] = 0; 
	while(l <= r) { 
		int u = q[++ l]; 
		for(int i = head[u];i;i = edge[i].next) { 
			int v = edge[i].v; 
			if(dis[v] > dis[u] + edge[i].l) { 
				dis[v] = dis[u] + edge[i].l; 
				if(!vis[v]) {q[++ r] = v,vis[v] = 1;} 
			} 
		} 
		vis[u] = 0; 
	} 
} 
void work1(int X) { 
	spfa(1); 
	int Q = read();int k = read(),s =  read(); 
	for(int v,p;Q --;) { 
		v = (read() + k * lastans - 1) % n + 1; 
		p = (read() + k * lastans) % (s + 1); 
		if(p >= X) printf("%d\n",dis[v]),lastans = dis[v]; 
		else puts("0"),lastans = 0; 
	} 
} 
int dad[maxn][25],h[maxn][25],deep[maxn]; 
void dfs(int x,int fa) {  
	for(int i = 0;dad[x][i];++ i) { 
		dad[x][i + 1] = dad[dad[x][i]][i]; 
			h[x][i + 1] = std::min(h[x][i],h[dad[x][i]][i]);  
	} 
	for(int i = head[x];i;i = edge[i].next) { 
		int v = edge[i].v; 
		if(v == fa) continue; 
		dis[v] = dis[x] + edge[i].l; 
		h[v][0] = edge[i].a; 
		dad[v][0] = x; 
		dfs(v,x); 
	} 
} 
int Jump(int x,int p) { 
	 for(int i = 20;i >= 0;-- i) 
		if(h[x][i] > p) x = dad[x][i];
	return lastans = dis[x]; 
} 
void work2() { 
	dfs(1,0); 
	int Q = read();int k = read(),s = read(); 
	for(int v,p;Q --;) { 
		v = (read() + k * lastans - 1) % n + 1; 
		p = (read() + k * lastans) % (s + 1); 
		printf("%d\n",Jump(v,p)); 
	} 
} 
void init() { 
	lastans = 0; 
	n = read(),m = read(); int cnt = 0; 
	for(int u,v,l,a,i = 1;i <= m;++ i) { 
		u = read(),v = read(),l = read(),a = read();  
		add_edge(u,v,l,a); add_edge(v,u,l,a);
		A[i] = a; 
		if(A[i] != A[i - 1]) cnt ++; 
	} 	
	if(cnt == 1) work1(A[1]); 
	else if(m == n - 1) work2(); 
} 
int main() { 
	//freopen("return4.in","r",stdin); //freopen("return.out","w",stdout); 
	int t = read(); while(t --) { 
		memset(head,0,sizeof head); num = 0; lastans = 0;
		init(); 
	} 
	return 0; 
} 

CompilationN/AN/ACompile OKScore: N/A

Testcase #1291.67 us2 MB + 320 KBAcceptedScore: 5

Testcase #211.066 ms5 MB + 184 KBRuntime ErrorScore: 0

Testcase #311.086 ms5 MB + 188 KBRuntime ErrorScore: 0

Testcase #411.101 ms5 MB + 196 KBRuntime ErrorScore: 0

Testcase #513.463 ms5 MB + 620 KBRuntime ErrorScore: 0

Testcase #61.065 s45 MB + 620 KBRuntime ErrorScore: 0

Testcase #72.643 ms2 MB + 852 KBAcceptedScore: 5

Testcase #82.615 ms2 MB + 856 KBAcceptedScore: 5

Testcase #92.629 ms2 MB + 852 KBAcceptedScore: 5

Testcase #10586.582 ms574 MB + 544 KBRuntime ErrorScore: 0

Testcase #11547.327 ms574 MB + 544 KBRuntime ErrorScore: 0

Testcase #1229.799 ms19 MB + 104 KBRuntime ErrorScore: 0

Testcase #1329.903 ms19 MB + 104 KBRuntime ErrorScore: 0

Testcase #1429.937 ms19 MB + 100 KBRuntime ErrorScore: 0

Testcase #15503.6 us2 MB + 496 KBRuntime ErrorScore: 0

Testcase #16499.61 us2 MB + 496 KBRuntime ErrorScore: 0

Testcase #1729.874 ms19 MB + 100 KBRuntime ErrorScore: 0

Testcase #1829.724 ms19 MB + 100 KBRuntime ErrorScore: 0

Testcase #1929.862 ms19 MB + 100 KBRuntime ErrorScore: 0

Testcase #2029.715 ms19 MB + 100 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-17 23:43:27 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠