Submission #1151080
Source Code Expand
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i < (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln() fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const int N = 1000005;
const int P = 1e9 + 7;
const int inf = 1e9;
const LL Inf = 1e15;
inline int IN(){
char ch = getchar(); int x = 0, f = 0;
while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
while(ch >= '0' && ch <= '9'){
x = (x << 1) + (x << 3) + ch - 48;
ch = getchar();
}
return f ? (-x) : x;
}
inline int Pow(int x, int y, int p){
int an = 1;
for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
return an;
}
void renew(int &x, int y){
x += y;
if(x < 0) x += P;
else if(x >= P) x -= P;
}
template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}
int n, Q, etot;
int ue[N], ve[N], we[N];
void adde(int x, int y, int z){
++etot;
ue[etot] = x;
ve[etot] = y;
we[etot] = z;
}
VI V[N];
void addx(int x, int y){
V[x].pb(y);
V[1].pb(y + (n - x + 1) * 2);
}
int id[N], fa[N];
int get(int x){
return (fa[x] == x) ? x : fa[x] = get(fa[x]);
}
int main(){
scanf("%d%d", &n, &Q);
REP(i, 1, Q){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
++a, ++b;
adde(a, b, c);
addx(a, c + 1);
addx(b, c + 2);
}
set<int> st;
REP(i, 1, n){
for(int v : V[i]) st.insert(v - 2 * i);
adde(i, i % n + 1, 2 * i + (*(st.begin())));
}
REP(i, 1, etot) id[i] = i;
REP(i, 1, n) fa[i] = i;
sort(id + 1, id + etot + 1, [&](const int &a, const int &b){return we[a] < we[b];});
LL ans = 0;
REP(i, 1, etot){
int tt = id[i];
int x = get(ue[tt]), y = get(ve[tt]);
if(x != y){
fa[x] = y;
ans += we[tt];
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Zigzag MST |
User |
syc19999 |
Language |
C++14 (GCC 5.4.1) |
Score |
1300 |
Code Size |
2603 Byte |
Status |
AC |
Exec Time |
562 ms |
Memory |
82800 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:87:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &Q);
^
./Main.cpp:90:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a, &b, &c);
^
Judge Result
Set Name |
sample |
all |
Score / Max Score |
0 / 0 |
1300 / 1300 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt, sample-03.txt |
all |
sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
10 ms |
33024 KB |
01-02.txt |
AC |
432 ms |
76524 KB |
01-03.txt |
AC |
562 ms |
82800 KB |
01-04.txt |
AC |
30 ms |
38144 KB |
01-05.txt |
AC |
22 ms |
36864 KB |
01-06.txt |
AC |
26 ms |
37376 KB |
01-07.txt |
AC |
24 ms |
36224 KB |
01-08.txt |
AC |
26 ms |
36224 KB |
01-09.txt |
AC |
43 ms |
38400 KB |
01-10.txt |
AC |
237 ms |
55924 KB |
01-11.txt |
AC |
414 ms |
59888 KB |
01-12.txt |
AC |
464 ms |
70640 KB |
01-13.txt |
AC |
466 ms |
70640 KB |
01-14.txt |
AC |
463 ms |
70640 KB |
01-15.txt |
AC |
465 ms |
70640 KB |
01-16.txt |
AC |
463 ms |
70640 KB |
01-17.txt |
AC |
473 ms |
70640 KB |
01-18.txt |
AC |
86 ms |
44388 KB |
01-19.txt |
AC |
24 ms |
36224 KB |
01-20.txt |
AC |
33 ms |
36352 KB |
01-21.txt |
AC |
123 ms |
48376 KB |
01-22.txt |
AC |
355 ms |
68720 KB |
01-23.txt |
AC |
363 ms |
68720 KB |
01-24.txt |
AC |
26 ms |
39424 KB |
01-25.txt |
AC |
130 ms |
48880 KB |
01-26.txt |
AC |
30 ms |
38528 KB |
01-27.txt |
AC |
43 ms |
39680 KB |
01-28.txt |
AC |
193 ms |
54772 KB |
01-29.txt |
AC |
274 ms |
51568 KB |
01-30.txt |
AC |
299 ms |
61424 KB |
sample-01.txt |
AC |
10 ms |
33024 KB |
sample-02.txt |
AC |
10 ms |
33024 KB |
sample-03.txt |
AC |
10 ms |
33024 KB |