zoukankan      html  css  js  c++  java
  • CF1366F. Jog Around The Graph

    https://codeforc.es/contest/1366/problem/F

    这玩意↑可以点开放大看

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    void read (int &x) {
    	char ch = getchar(); x = 0;
    	while (!isdigit(ch)) ch = getchar();
    	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    } const int N = 2038, mod = 1e9 + 7;
    int n, m, q, res, mx, f[N][2];
    int cnt, h[N], to[N << 1], nxt[N << 1], d[N << 1];
    void add (int u, int v, int w) {
    	to[++cnt] = v, d[cnt] = w, nxt[cnt] = h[u], h[u] = cnt;
    }
    pair<int, int> t[N];  
    #define x first
    #define y second
    int Pow (int x, int y) {
    	int tmp = 1;
    	while (y) {
    		if (y & 1) tmp = tmp * x % mod;
    		x = x * x % mod, y >>= 1;
    	} return tmp;
    }
    signed main() {
    //	freopen ("data.in", "r", stdin);
    	read (n), read (m), read (q);
    	for (int i = 1, u, v, w; i <= m; ++i) {
    		read (u), read (v), read (w);
    		add (u, v, w), add (v, u, w); mx = max (mx, w);
    	}
    	for (int i = 2; i <= n; ++i) f[i][0] = -1;
    	for (int k = 1; k <= m; ++k) {
    		int p = (k & 1), tmp = 0;
    		for (int i = 1; i <= n; ++i) {
    			f[i][p] = -1; 
    			for (int j = h[i]; j; j = nxt[j]) {
    				if (f[to[j]][p ^ 1] >= 0)
    					f[i][p] = max (f[i][p], f[to[j]][p ^ 1] + d[j]);
    			}
    			tmp = max (tmp, f[i][p]); 
    		} res = (res + tmp) % mod;
    	}
    	for (int i = 1; i <= n; ++i) {
    		t[i].y = f[i][m & 1];
    		for (int j = h[i]; j; j = nxt[j])
    			t[i].x = max (t[i].x, d[j]);
    	}	
    	int inv = Pow (2, mod - 2);
    	sort (t + 1, t + n + 1);
    	for (int i = 1; i <= n; ++i) {
    		int l = 1, r = q - m;
    		if (t[i].y == -1) continue;
    		for (int j = 1; j < i; ++j) {
    			int sx = t[i].x - t[j].x, sy = t[j].y - t[i].y;
    			if (!sy) continue;
    			int t = ceil (1.0 * sy / sx);
    			l = max (l, t);
    		}
    		for (int j = i + 1; j <= n; ++j) {
    			int sx = t[i].x - t[j].x, sy = t[j].y - t[i].y;
    			if (!sy) { r = 0; break; }
    			int t = ceil (1.0 * sy / sx) - 1;
    			r = min (r, t);
    		} if (l > r) continue;
    		res = (res + (r - l + 1) * ((t[i].y * 2 + t[i].x * (l + r)) % mod) % mod * inv % mod) % mod;
    	}
    	return printf ("%lld
    ", res), 0;
    }
    
  • 相关阅读:
    静态嵌套类(Static Nested Class)和内部类(Inner Class)的不同?
    编写多线程程序有几种实现方式?
    文件拷贝
    如何实现对象克隆?
    c#如何保存richtextbox的rtf格式
    C#实现文件与二进制互转并存入数据库
    c#中绝对路径和相对路径
    C#实现MySQL数据库中的blob数据存储
    CSS控制文字,超出显示省略号
    ES6 语句判断简写
  • 原文地址:https://www.cnblogs.com/whx666/p/13369807.html
Copyright © 2011-2022 走看看