Submission #338056
Source Code Expand
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
int n = ni(), m = ni();
int[] from = new int[m];
int[] to = new int[m];
int[] deg = new int[n];
for(int i = 0;i < m;i++){
from[i] = ni()-1;
to[i] = ni()-1;
deg[from[i]] ^= 1;
deg[to[i]] ^= 1;
}
int mod = 1000000007;
long ret = pow(2, m+1, mod)+mod-2;
int[] tf = new int[n-1];
int[] tt = new int[n-1];
int[] tw = new int[n-1];
DJSet ds = new DJSet(n);
int[] has = new int[n];
Arrays.fill(has, -1);
for(int i = 0;i < n;i++){
if(deg[i] % 2 == 1){
has[i] = i;
}
}
int p = 0;
for(int i = 0;i < m;i++){
if(!ds.equiv(from[i], to[i])){
ds.union(from[i], to[i]);
tf[p] = from[i]; tt[p] = to[i]; tw[p] = (int)pow(2, i+1, mod);
p++;
}
}
int[][][] g = packWU(n, tf, tt, tw);
int[][] pars = parents(g, 0);
int[] par = pars[0], ord = pars[1];
int[] oe = new int[n];
for(int i = 0;i < n;i++){
if(deg[i] % 2 == 1)oe[i] = 1;
}
long all = ret;
for(int i = n-1;i >= 0;i--){
int cur = ord[i];
for(int[] e : g[cur]){
if(e[0] != par[cur]){
if(oe[e[0]] == 1){
oe[cur] ^= 1;
all += e[1];
}
}
}
}
out.println(all%mod);
}
public static int[][] parents(int[][][] g, int root)
{
int n = g.length;
int[] par = new int[n];
Arrays.fill(par, -1);
int[] dw = new int[n];
int[] pw = new int[n];
int[] dep = new int[n];
int[] q = new int[n];
q[0] = root;
for(int p = 0, r = 1;p < r;p++) {
int cur = q[p];
for(int[] nex : g[cur]){
if(par[cur] != nex[0]){
q[r++] = nex[0];
par[nex[0]] = cur;
dep[nex[0]] = dep[cur] + 1;
dw[nex[0]] = dw[cur] + nex[1];
pw[nex[0]] = nex[1];
}
}
}
return new int[][] {par, q, dep, dw, pw};
}
public static int[][][] packWU(int n, int[] from, int[] to, int[] w) {
int[][][] g = new int[n][][];
int[] p = new int[n];
for (int f : from)
p[f]++;
for (int t : to)
p[t]++;
for (int i = 0; i < n; i++)
g[i] = new int[p[i]][2];
for (int i = 0; i < from.length; i++) {
--p[from[i]];
g[from[i]][p[from[i]]][0] = to[i];
g[from[i]][p[from[i]]][1] = w[i];
--p[to[i]];
g[to[i]][p[to[i]]][0] = from[i];
g[to[i]][p[to[i]]][1] = w[i];
}
return g;
}
public static class DJSet {
public int[] upper;
public DJSet(int n) {
upper = new int[n];
Arrays.fill(upper, -1);
}
public int root(int x) {
return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
}
public boolean equiv(int x, int y) {
return root(x) == root(y);
}
public boolean union(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (upper[y] < upper[x]) {
int d = x;
x = y;
y = d;
}
upper[x] += upper[y];
upper[y] = x;
}
return x == y;
}
public int count() {
int ct = 0;
for (int u : upper)
if (u < 0)
ct++;
return ct;
}
}
public static long pow(long a, long n, long mod) {
// a %= mod;
long ret = 1;
int x = 63 - Long.numberOfLeadingZeros(n);
for (; x >= 0; x--) {
ret = ret * ret % mod;
if (n << 63 - x < 0)
ret = ret * a % mod;
}
return ret;
}
static int[][] packD(int n, int[] from, int[] to) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int f : from)
p[f]++;
for (int i = 0; i < n; i++)
g[i] = new int[p[i]];
for (int i = 0; i < from.length; i++) {
g[from[i]][--p[from[i]]] = to[i];
}
return g;
}
public static void main(String[] args) throws Exception
{
long S = System.currentTimeMillis();
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
solve();
out.flush();
long G = System.currentTimeMillis();
tr(G-S+"ms");
}
private static boolean eof()
{
if(lenbuf == -1)return true;
int lptr = ptrbuf;
while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
try {
is.mark(1000);
while(true){
int b = is.read();
if(b == -1){
is.reset();
return true;
}else if(!isSpaceChar(b)){
is.reset();
return false;
}
}
} catch (IOException e) {
return true;
}
}
private static byte[] inbuf = new byte[1024];
static int lenbuf = 0, ptrbuf = 0;
private static int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
// private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private static double nd() { return Double.parseDouble(ns()); }
private static char nc() { return (char)skip(); }
private static String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private static char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private static char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private static int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private static int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
Submission Info
Submission Time |
|
Task |
C - ドライブ |
User |
uwi |
Language |
Java (OpenJDK 1.7.0) |
Score |
110 |
Code Size |
6965 Byte |
Status |
AC |
Exec Time |
1992 ms |
Memory |
84020 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
40 / 40 |
70 / 70 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
Subtask1 |
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt |
Subtask2 |
subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
412 ms |
20888 KB |
sample_02.txt |
AC |
408 ms |
20632 KB |
subtask1_01.txt |
AC |
414 ms |
20688 KB |
subtask1_02.txt |
AC |
407 ms |
20664 KB |
subtask1_03.txt |
AC |
405 ms |
20740 KB |
subtask1_04.txt |
AC |
779 ms |
21504 KB |
subtask1_05.txt |
AC |
451 ms |
22104 KB |
subtask1_06.txt |
AC |
432 ms |
22344 KB |
subtask1_07.txt |
AC |
428 ms |
22560 KB |
subtask1_08.txt |
AC |
432 ms |
22172 KB |
subtask1_09.txt |
AC |
440 ms |
22308 KB |
subtask1_10.txt |
AC |
450 ms |
22348 KB |
subtask1_11.txt |
AC |
461 ms |
22308 KB |
subtask1_12.txt |
AC |
434 ms |
22436 KB |
subtask1_13.txt |
AC |
443 ms |
22452 KB |
subtask1_14.txt |
AC |
435 ms |
21792 KB |
subtask1_15.txt |
AC |
416 ms |
21568 KB |
subtask1_16.txt |
AC |
423 ms |
22416 KB |
subtask1_17.txt |
AC |
424 ms |
21740 KB |
subtask1_18.txt |
AC |
417 ms |
21204 KB |
subtask2_01.txt |
AC |
1976 ms |
84020 KB |
subtask2_02.txt |
AC |
1965 ms |
83976 KB |
subtask2_03.txt |
AC |
1741 ms |
83684 KB |
subtask2_04.txt |
AC |
1992 ms |
83904 KB |
subtask2_05.txt |
AC |
1736 ms |
73904 KB |
subtask2_06.txt |
AC |
1895 ms |
73956 KB |
subtask2_07.txt |
AC |
1462 ms |
74784 KB |
subtask2_08.txt |
AC |
1790 ms |
74024 KB |
subtask2_09.txt |
AC |
1912 ms |
83952 KB |
subtask2_10.txt |
AC |
698 ms |
37392 KB |
subtask2_11.txt |
AC |
548 ms |
30120 KB |
subtask2_12.txt |
AC |
1209 ms |
60328 KB |
subtask2_13.txt |
AC |
1672 ms |
72988 KB |
subtask2_14.txt |
AC |
1798 ms |
72868 KB |
subtask2_15.txt |
AC |
529 ms |
28288 KB |